Create simple struts2 project using maven commands

Let's see how we can create a very simple project structure for Struts2 application using maven in command prompt or terminal.

Note: Below is an example demonstrated on Mac OS X using terminal

Lets first set the JAVA_HOME and PATH for maven ( my version is maven 3.3.3)

localhost:~ code2care$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/
localhost:~ code2care$ export PATH=/Users/code2care/Setups/apache-maven-3.3.3/bin:$PATH

Now let's run the maven archetype: generate a command to display the project stub :

localhost:~ code2care$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)

9: remote -> (an archetype web 3.0 + struts2 (bootstrap + jquery) + JPA 2.1 with struts2 login system)
167: remote -> com.jgeppert.struts2.jquery:struts2-jquery-archetype-base (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Plugin.)
168: remote -> com.jgeppert.struts2.jquery:struts2-jquery-archetype-mobile (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Mobile Plugin.)
169: remote -> com.jgeppert.struts2.jquery:struts2-jquery-bootstrap-archetype-grid (This Archetype provides a Webapp Configuration ready for the Struts2 jQuery Grid Plugin and the Struts2
743: remote -> org.apache.struts:struts2-archetype-angularjs (-)
744: remote -> org.apache.struts:struts2-archetype-blank (-)
745: remote -> org.apache.struts:struts2-archetype-convention (-)
746: remote -> org.apache.struts:struts2-archetype-dbportlet (-)
747: remote -> org.apache.struts:struts2-archetype-plugin (-)
748: remote -> org.apache.struts:struts2-archetype-portlet (-)
749: remote -> org.apache.struts:struts2-archetype-starter (-)

I have just listed out a few struts2 projects that may be useful for us

Lets select number 744 : org.apache.struts:struts2-archetype-blank

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 644: 744

Select the struts 2 version that you want : I have selected 25 i.e. version 2.3.24

Choose org.apache.struts:struts2-archetype-blank version:

1: 2.2.1
3: 2.2.3
5: 2.3.3
6: 2.3.4
8: 2.3.7
9: 2.3.8
10: 2.3.12
11: 2.3.14
15: 2.3.15
19: 2.3.16
23: 2.3.20
25: 2.3.24
26: 2.5-BETA1
Choose a number: 26: 25
Downloaded: (39 KB at 13.2 KB/sec)
Downloaded: (3 KB at 4.0 KB/sec)
Define the properties : groupId, artifactId, version and package,
Define value for property 'groupId': : org.code2care.struts2
Define value for property 'artifactId': : HelloStruts2
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  org.code2care.struts2: : 
Confirm properties configuration:
groupId: org.code2care.struts2
artifactId: HelloStruts2
version: 1.0-SNAPSHOT
package: org.code2care.struts2
 Y: : Y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: struts2-archetype-blank:2.3.24
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.code2care.struts2
[INFO] Parameter: artifactId, Value: HelloStruts2
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: org.code2care.struts2
[INFO] Parameter: packageInPathFormat, Value: org/code2care/struts2
[INFO] Parameter: package, Value: org.code2care.struts2
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: org.code2care.struts2
[INFO] Parameter: artifactId, Value: HelloStruts2
[INFO] project created from Archetype in dir: /Users/code2care/HelloStruts2
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:37 min
[INFO] Finished at: 2015-09-15T11:47:15+05:30
[INFO] Final Memory: 13M/98M
[INFO] ------------------------------------------------------------------------
localhost:~ code2care$ 

That's it! You should see BUILD SUCCESS and the location where the project HelloStruts2 just above that info line.

Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.