{:.no_toc}
Struts 2 provides several Maven archetypes that create a starting point for our own applications.
Contents
A recommended way to start with Struts2 archetypes is to use archetype:generate
goal with filter
parameter.
mvn archetype:generate -Dfilter=org.apache:struts
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-convention
See the Struts 2 Blank Archetype page for more information, including some basic Maven information, how to build and run the app, and basic application information.
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-blank
The Starter archetype creates a more featured application using several common technologies used in production applications.
-Sitemesh integration
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-starter
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-angularjs
The Portlet blank archetype creates a minimally populated JSR 168 portlet.
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-portlet
The Portlet database archetype creates a simple JSR 168 portlet that displays the contents of a database table.
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-dbportlet
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myPlugin \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-plugin
Run the following command from your new project's parent directory. The project will be created in a sub-directory named after the artifactId
parameter.
The first two parameters, groupId
and artifactId
, should be set according to your needs:
groupId
This should be the root package of your application, e.g., com.mycompany.myapp.artifactId
Names the project directory that will be created in the current directory.mvn archetype:generate -B \ -DgroupId=tutorial \ -DartifactId=tutorial \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-blank
If the above command will fail because of missing archetypes in central repository, you can try to use staging repository.
Add staging repository to your settings.xml
<settings> <profiles> <profile> <id>staging</id> <repositories> <repository> <id>archetype</id> <url>https://repository.apache.org/content/repositories/snapshots/</url> <releases> <enabled>true</enabled> <checksumPolicy>fail</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>warn</checksumPolicy> </snapshots> </repository> </repositories> </profile> </profiles> </settings>
Use staging
profile in the command.
mvn archetype:generate -B \ -DgroupId=tutorial \ -DartifactId=tutorial \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-blank \ -Pstaging
The -B
option runs archetype:generate
in batch mode; it avoids a prompt to confirm our settings.
Parameter | Description |
---|---|
groupId | The id for the group the application belongs to. Usually is the root package for applications in your company, e.g. com.mycompany |
artifactId | The id for the project. The project will be created a sub-directory named after this parameter. |
archetypeGroupId | The group id of the archetype. Will always be org.apache.struts for Struts archetypes |
archetypeArtifactId | The id of the archetype |
These commands are used from the directory created by the archetype plugin (the project's sub-directory that was created in the previous step).
mvn install
mvn test
mvn clean
mvn package
mvn initialize
mvn jetty:run