Home > Guides > Core Developers Guide > Struts 2 Maven Archetypes |
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 work with the archetype catalog.
mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-convention \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
The Struts 2 Blank Archetype ("blank-archetype") provides a minimal, but complete, Struts 2 application. It demonstrates some of the most basic Struts 2 concepts.
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 \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
The Starter archetype creates a more featured application using several common technologies used in production applications.
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-starter \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myWebApp \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-angularjs \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
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 \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
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 \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ -DartifactId=myPlugin \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-plugin \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> \ -DremoteRepositories=http://struts.apache.org
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
artifactId
mvn archetype:generate -B \ -DgroupId=tutorial \ -DartifactId=tutorial \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-blank \ -DarchetypeVersion=<CURRENT_STRUTS_VERSION> -DremoteRepositories=http://struts.apache.org
where <CURRENT_STRUTS_VERSION> is archetype's version you want to use, eg. 2.3.15.1
If the above command will fail because of missing archetypes in central repository, you can try to use staging repository like below
mvn archetype:generate -DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/
or this
mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/
The -B
option runs archetype:generate
in batch mode; it avoids a prompt to confirm our settings.
Parameter | Description |
---|---|
| The id for the group the application belongs to. Usually is the root package for applications in your company, e.g. com.mycompany |
| The id for the project. The project will be created a sub-directory named after this parameter. |
| The group id of the archetype. Will always be |
| The id of the archetype |
| The version of the archetype |
| (Optional) The base Java package to use for generated source code. Defaults to |
| (Optional) A list of remote repositories that contain 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 idea:idea
mvn eclipse:eclipse -Dwtpversion=1.5
mvn test
mvn clean
mvn package
mvn initialize
mvn jetty:run