Struts 2 provides several Maven archetypes to create complete applications that can be used as the basis of our own applications. Once the archetype project is generated it can be extended to implement our application's functionality.
Available Archetypes
The following archetypes are available:
The Blank Archetype (struts2-archetype-blank)
Nearly-minimal Struts 2 application, includes only an example package/action and some minimal tests.
Features
- XML-based configuration, demonstrates including additional config file
- Example actions
- Resource bundle
- XML-based validation
- Unit-testing
The Starter Archetype (struts2-archetype-starter)
The Starter archetype creates a more featured application using several common technologies used in production applications.
Features
- Sitemesh integration
- Action example (both instantiated through Spring and Struts itself)
- Validation example (action and action-alias level)
- Conversion example (global and action level)
- Resource bundle (both global, action and package level)
The Portlet Blank Archetype (struts2-archetype-portlet)
The Portlet blank archetype creates a minimally populated JSR 168 portlet.
Features
- View, Edit, and Help mode examples
- Simple form for preferences in Edit mode
- Can be deployed as a servlet or portlet application
- Can use Maven Jetty plugin to deploy as a servlet webapp
The Portlet Database Archetype (struts2-archetype-dbportlet)
The Portlet database archetype creates a simple JSR 168 portlet that displays the contents of a database table.
Features
- Uses Spring and Hsql to show a real database query
- Builtin caching of query results
- View, Edit, and Help mode examples
- Simple form for preferences in Edit mode
- Can be deployed as a servlet or portlet application
- Can use Maven Jetty plugin to deploy as a servlet webapp
Creating an Application Using an Archetype
From a working directory for your project, run the following command:
mvn archetype:generate -DgroupId=tutorial \ -DartifactId=tutorial \ -DarchetypeGroupId=org.apache.struts \ -DarchetypeArtifactId=struts2-archetype-blank \ -DarchetypeVersion=2.1.6
Archetype Parameters
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 |
|
A list of remote repositories that contain the archetype. If deployed to the standard Maven repository or locally, this is optional |
The Archetype will create a ready-to-run Struts project. Just run "mvn install" to build.
Command Quick Reference
These commands are used from the directory created by the archetype plugin.
- To build
mvn install
- To create IntelliJ IDEA project files
mvn idea:idea
- To create Eclipse project files
mvn eclipse:eclipse
- To run test cases
mvn test
- To clean up (removes generated artifacts)
mvn clean
- To package (creates a WAR file)
mvn package
- To grab necessary JAR files etc.
mvn initialize
- To run it with Jetty
mvn jetty:run