Archive

Archive for February, 2010

Maven and Struts 1

February 10, 2010 7 comments

Maven archetype can be used to generate blank projects. However, the mvn archetype:generate command does not give an option to generate an empty struts project with Struts 1. To generate a Struts 1.x project we need to install the struts blank archetype. Use the following commands to download and install struts blank archetype in the local repository.

svn co http://svn.apache.org/repos/asf/struts/maven/trunk/struts-archetype-blank
cd struts-archetype-blank
mvn install

Now to generate a project use the following command

mvn archetype:generate -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts-archetype-blank -DarchetypeVersion=1.3.5-SNAPSHOT -DgroupId=com.wordpress.codesilo -DpackageName=com.wordpress.codesilo -DartifactId=test-struts

Now we will test this on JBoss AS. Set a variable JBOSS_HOME in bash_profile and change the plugins section generated in the pom.xml file above to the following.

 <plugins>
 <plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>jboss-maven-plugin</artifactId>
 <version>1.4</version>
 <configuration>
 <jbossHome>/${JBOSS_HOME}</jbossHome>
 <serverName>web</serverName>
 <fileName>target/test-struts.war</fileName>
 </configuration>
 </plugin>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
 <source>1.5</source>
 <target>1.5</target>
 </configuration>
 </plugin>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-war-plugin</artifactId>
 <configuration>
 <webResources>
 <webResource>
 <directory>
 ${basedir}/src/main/webapp/WEB-INF</directory>
 <includes>
 <include>web.xml</include>
 </includes>
 <targetPath>WEB-INF</targetPath>
 <filtering>true</filtering>
 </webResource>
 </webResources>
 </configuration>
 </plugin>
 </plugins>

Now we will use the maven JBoss plugin to deploy the war generated above. Use the following command to deploy the war file.

mvn jboss:hard-deploy

(To undeploy use the command mvn jboss:hard-undeploy)

The war will be deployed to the following dir ($JBOSS_HOME/server/web/deploy) (in JBoss 5). If Jboss 4 is used, change the serverName above to “default”.

On starting Jboss we will see an exception ….
java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
This can be corrected by removing the jar that is included by the struts-archetype-blank plugin.
Change the following in the pom.xml

 <dependency>
 <groupId>org.apache.struts</groupId>
 <artifactId>struts-core</artifactId>
 <version>1.3.5</version>
 </dependency>

to

 <dependency>
 <groupId>org.apache.struts</groupId>
 <artifactId>struts-core</artifactId>
 <version>1.3.5</version>
 <exclusions>
 <exclusion>
 <groupId>xml-apis</groupId>
 <artifactId>xml-apis</artifactId>
 </exclusion>
 </exclusions>
 </dependency>

The server will now start without any exceptions.

Advertisements

Setting up Ubuntu for development

February 2, 2010 1 comment

I had to reinstall Ubuntu recently and this blog is a summary of setting Ubuntu up for development.

Installing Maven:

sudo apt-get install maven2

In the .bash_profile file in the $HOME directory set the MAVEN_REPO variable and export it. Add this line in the file : export MAVEN_REPO=$HOME/.m2/repository

Installing Sun JDK:

sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
sudo update-java-alternatives -l
sudo update-java-alternatives -s java-6-sun

In the .bash_profile file again, add these lines —
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

Update: For installing JDK on Lucid Lynx read this post.

Installing MySql Server:

sudo apt-get install mysql-server

Set the root password when prompted.

Installing Samba:

sudo apt-get install samba smbfs

Installing openssh:

sudo apt-get install openssh-server openssh-client


Installing Ruby and RoR:
This link is a very good summary of doing that in Karmic Koala.

Installing Subversion:

sudo apt-get install subversion

Installing Client for Subversion:
RapidSVN is a very good tool for Ubuntu but recently I tried  RabbitVCS. This is in active development and is very close to TortoiseSVN in Windows.
To install RabbitVCS you need to download the deb package from their website and and install it using the following command (rabbitvcs_0.12.1-2~karmic_all.deb is the downloaded file)

sudo dpkg -i rabbitvcs_0.12.1-2~karmic_all.deb

Installing Eclipse, SpringIDE and Maven Plugin for Eclipse:
Eclipse can be easily installed by using package manager but I ran into some problems with the maven plugin when I used the eclipse that came with Karmic. When I used the Eclipse from their download site ,I did not have the problems.
Get SpringIDE plugin by providing this site in the “install new software” option in Eclipse: http://springide.org/updatesite. The ADJT features were giving problems when installing this plugin so I deselected them.
Get maven plugin from here : http://m2eclipse.sonatype.org/update

Getting started with Maven on Ubuntu

February 1, 2010 Leave a comment

Maven is a project management tool. Installing it in Ubuntu is very straightforward. Run the following command in the terminal to install Maven.

sudo apt-get install maven2

To create a simple project using maven use this command

mvn archetype:generate

and when prompted enter option “15”. This creates a quickstart project. Read more about this command here.
Set a MAVEN_REPO environment variable by adding this line in the .profile file in the home folder
export MAVEN_REPO=/home/<user>/.m2/repository ; Replace the user with the user-name on Ubuntu.
This variable will be used by Eclipse.
In the project created earlier, run this command

mvn clean install

This will clean, build and install your project. Note: this command has to be run in the dir of the project that contains the pom.xml file. The jar file created from the build can be found in the target directory.
Here is the directory structure after the build:(The following values were used to create the project by using the archetype plugin — groupId: test;artifactId: test;version: 1.0-SNAPSHOT;package: com.codesilo.test)

test
|– pom.xml
|– src
|   |– main
|   |   `– java
|   |       `– com
|   |           `– codesilo
|   |               `– test
|   |                   `– App.java
|   `– test
|       `– java
|           `– com
|               `– codesilo
|                   `– test
|                       `– AppTest.java
`– target
|– classes
|   `– com
|       `– codesilo
|           `– test
|               `– App.class
|– maven-archiver
|   `– pom.properties
|– surefire-reports
|   |– TEST-com.codesilo.test.AppTest.xml
|   `– com.codesilo.test.AppTest.txt
|– test-1.0-SNAPSHOT.jar
`– test-classes
`– com
`– codesilo
`– test
`– AppTest.class

Read more about build lifecycle here.

Technorati Tags: , , , , , , , ,

Categories: Maven, Ubuntu