Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning

DEPRECATED: moved to http://struts.apache.org/maven-archetypes/

 

Struts 2 provides several Maven archetypes that create a starting point for our own applications.

Contents

Table of Contents
maxLevel3
minLevel2

...

...

outlinetrue
indent1em
stylenone

Quickstart

A recommended way to start with Struts2 archetypes is to work with the archetype catalog.

Code Block

mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/

...

  • Convention-based validation
  • Example actions
  • Package-level resource bundle
  • Unit-testing
  • Google AppEgine aware
Code Block

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 Blank Archetype (struts2-archetype-blank)

Excerpt Include
Struts 2 Blank Archetype
Struts 2 Blank Archetype
nopaneltrue

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.

Code Block

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

...

  • Sitemesh integration
  • Action example (instantiated both through Spring and Struts)
  • Spring integration
  • Validation example (action and action-alias level)
  • Conversion example (global and action level)
  • Resource bundle (both global, action and package level)
Code Block

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

...

  • Convention-based Action Configuration
  • Example actions with JSON Result
  • Example for AngularJS and Struts2 Integration
Code Block

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

...

  • 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 with the pluto-embedded profile (usage 'mvn jetty:run -Ppluto-embedded', then access http://localhost:8080/<artifactId>/pluto/index.jsp)
Code Block

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

...

  • 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
Code Block

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

...

  • Example new result type
  • Example XML-based configuration
Code Block

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

...

  • 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.
Code Block

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

...

If the above command will fail because of missing archetypes in central repository, you can try to use staging repository like below

Code Block

mvn archetype:generate -DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/

or this

Code Block

mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/

...

These commands are used from the directory created by the archetype plugin (the project's sub-directory that was created in the previous step).

  • To build
Code Block

   mvn install
  • To create IntelliJ IDEA project files
Code Block

   mvn idea:idea
  • To create Eclipse project files
Code Block

   mvn eclipse:eclipse -Dwtpversion=1.5
  • To run test cases
Code Block

   mvn test
  • To clean up (removes generated artifacts)
Code Block

   mvn clean
  • To package (creates a WAR file)
Code Block

   mvn package
  • To grab necessary JAR files etc.
Code Block

   mvn initialize
  • To run it with Jetty
Code Block

   mvn jetty:run