Archive

Posts Tagged ‘archetype:generate’

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.