Thursday, August 16, 2012

Add new struts2 maven project in eclipse

1. Click File > New > Project... 
2. New Project will be prompted. Choose Maven > Maven Project. Click Next.
3. New Maven Project will be prompted. Click next.
4. Choose Nexus Indexer for Catalog. highlight maven-archetype-webapp(Artifact Id) and click next.
5. Fill in the Group Id, Artifact Id, version and click Finish.
6. Set the tools.jar dependence in your pom.xml. 

Add

 
<profiles>
      <profile>
          <id>default-tools.jar</id>
          <activation>
              <property>
                  <name>java.vendor</name>
                  <value>Sun Microsystems Inc.</value>
              </property>
          </activation>
          <dependencies>
              <dependency>
                  <groupId>com.sun</groupId>
                  <artifactId>tools</artifactId>
                  <version>1.5.0</version>
                  <scope>system</scope>
                  <systemPath>C:/Program Files/Java/jdk1.6.0_23/lib/tools.jar</systemPath>
              </dependency>
          </dependencies>
      </profile>
  </profiles>

This will solve the Missing artifact com.sun:tools:jar:1.5.0:system problem.

7. Add strut2
There are 2 ways to do it:

a. Right click the source folder, Maven > Add Dependency. Type struts2-core. Then, highlight the org.apache.struts struts2-core and click ok.

b. Add below in pom.xml

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

8. Add log4j and javassist dependencies.
<dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.2.1.1</version>
    </dependency>
  </dependencies>

** log4j is encouraged to be manually added to prevent Missing artifact log4j:log4j:bundle:1.2.16:compile

** Final pom.xml attached on below

9. Right click on the project: Run as > Maven install. This will build war file in the target folder of your project. 

10. Deploy the war file.

[attached]