...
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 Struts action example (both instantiated through Spring and Struts itself)
- A simple Struts validation Validation example (action and action-alias level)
- A Simple Struts conversion Conversion example (global and action level)
- A simple Struts resource Resource bundle (both global, action and package level)
Installing Maven archetype for Struts 2
- Change directory to the maven archetype directory eg. from Struts' root directory (You will need the Struts 2 source from SVN)
Code Block cd ./struts2-archetype-starter <press enter>
- Run the following command to install Struts2 maven archetype into one's local maven repository (typically at ~/.m2/repository where ~ is the user directory)
Code Block mvn install
- If "build successful" is shown at the console after execution of the above command, the Struts2 Maven archetype plugin is successfully installed.
Create Struts Web Application Template
To create a workable template:-
- Change directory to where the web application 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 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 template
Following are some Maven command that might be handy when using the generated template :-
- To compile
Code Block mvn compileeclipse:eclipse
- To run test cases
Code Block mvn test
...
- To grab necessary JAR files etc.
Code Block mvn initialize
- To run it with Jetty6 Jetty
Code Block mvn jetty6jetty:run