...
Warning |
---|
This |
...
page is deprecated and replaced by the Struts 2 Maven Archetypes page. It is being kept (for now) for release note links. |
...
Struts provides several Maven Archetypes that create working applications based on a template.
Available Archetypes
The following archetypes are available:
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
Features
The created template contains :-
- Sitemesh integration build in
- A simple SAF2 action example (both instantiated through Spring and SAF2 Struts itself)
- A simple SAF2 validation Validation example (action and action-alias level)
- A Simple SAF2 conversion Conversion example (global and action level)
- A simple SAF2 resource Resource bundle (both global, action and package level)
Installing SAF2 maven archetype
- Change directory to SAF2's maven archetype directory eg. from SAF2's root directory (You will need the SAF2 source from SVN)
Code Block cd ./archetype <press enter>
- Run the following command to install SAF2 maven archetype into one's local maven repository (typically at ~/.m2/repository where ~ is the user directory)
Code Block mvn install
- If "build succesfull" is shown at the console after execution of the above command, the SAF2 maven archetype plugin is successfully installed.
Create SAF2 Web app template
To create a workable template of SAF2 :-
- Change directory to where the web app template is to be created eg. assuming the directory to be myWebApp.
Code Block mkdir /home/tmjee/myWebApp cd /home/tmjee/myWebApp
...
Root java package | com.myCompany.mySystem |
The webapp war name | myWebApp |
...
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:
Code Block |
---|
mvn archetype:create -DgroupId=tutorial \ -DartifactId=tutorial \ -DarchetypeGroupId=org.apache.struts |
...
\ -DarchetypeArtifactId= |
...
struts2-archetype |
...
-starter \
-DarchetypeVersion=2.0.11.2
|
This table describes the parameters used above:
Name | 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 base Java package to use for generated source code. Defaults to |
| The group id of the archetype. Will always be |
| The id of the archetype |
| The version of the archetype |
| 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-run Struts project. Just run "mvn install" to build.
Command Quick Reference
- To build
Code Block mvn install
- To create IntelliJ IDEA project files
Code Block mvn idea:idea
- To create Eclipse project files
Using the created SAF2 Web app template
Following are some maven command that might be handy when using the generated SAF2 web app template :-
- To compile
Code Block mvn compileeclipse:eclipse
- TO To run test cases
Code Block mvn test
...
- To package
Code Block mvn package
- To grab necessary jar JAR files etc.
Code Block mvn initialize
- To run it with Jetty6 Jetty
Code Block mvn jetty6jetty:run