| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"/> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
| <meta name="Date-Revision-yyyymmdd" content="20140918"/> |
| <meta http-equiv="Content-Language" content="en"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| |
| <title>Maven Archetypes</title> |
| |
| <link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,400italic,600italic,700italic" rel="stylesheet" type="text/css"> |
| <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> |
| <link href="/css/main.css" rel="stylesheet"> |
| <link href="/css/custom.css" rel="stylesheet"> |
| <link href="/highlighter/github-theme.css" rel="stylesheet"> |
| |
| <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> |
| <script type="text/javascript" src="/bootstrap/js/bootstrap.js"></script> |
| <script type="text/javascript" src="/js/community.js"></script> |
| </head> |
| <body> |
| |
| <a href="http://github.com/apache/struts" class="github-ribbon"> |
| <img style="position: absolute; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"> |
| </a> |
| |
| <header> |
| <nav> |
| <div role="navigation" class="navbar navbar-default navbar-fixed-top"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <button type="button" data-toggle="collapse" data-target="#struts-menu" class="navbar-toggle"> |
| Menu |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <a href="/index.html" class="navbar-brand logo"><img src="/img/struts-logo.svg"></a> |
| </div> |
| <div id="struts-menu" class="navbar-collapse collapse"> |
| <ul class="nav navbar-nav"> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Home<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/index.html">Welcome</a></li> |
| <li><a href="/download.cgi">Download</a></li> |
| <li><a href="/releases.html">Releases</a></li> |
| <li><a href="/announce.html">Announcements</a></li> |
| <li><a href="http://www.apache.org/licenses/">License</a></li> |
| <li><a href="https://www.apache.org/foundation/thanks.html">Thanks!</a></li> |
| <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Support<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/mail.html">User Mailing List</a></li> |
| <li><a href="https://issues.apache.org/jira/browse/WW">Issue Tracker</a></li> |
| <li><a href="/security.html">Reporting Security Issues</a></li> |
| <li class="divider"></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Migration+Guide">Version Notes</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Security+Bulletins">Security Bulletins</a></li> |
| <li class="divider"></li> |
| <li><a href="/maven/project-info.html">Maven Project Info</a></li> |
| <li><a href="/maven/struts2-core/dependencies.html">Struts Core Dependencies</a></li> |
| <li><a href="/maven/struts2-plugins/modules.html">Plugin Dependencies</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Documentation<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/birdseye.html">Birds Eye</a></li> |
| <li><a href="/primer.html">Key Technologies</a></li> |
| <li><a href="/kickstart.html">Kickstart FAQ</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Home">Wiki</a></li> |
| <li class="divider"></li> |
| <li><a href="/getting-started/">Getting Started</a></li> |
| <li><a href="/security/">Security Guide</a></li> |
| <li><a href="/core-developers/">Core Developers Guide</a></li> |
| <li><a href="/tag-developers/">Tag Developers Guide</a></li> |
| <li><a href="/maven-archetypes/">Maven Archetypes</a></li> |
| <li><a href="/plugins/">Plugins</a></li> |
| <li><a href="/maven/struts2-core/apidocs/index.html">Struts Core API</a></li> |
| <li><a href="/tag-developers/tag-reference.html">Tag reference</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/FAQs">FAQs</a></li> |
| <li><a href="http://cwiki.apache.org/S2PLUGINS/home.html">Plugin registry</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Contributing<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/youatstruts.html">You at Struts</a></li> |
| <li><a href="/helping.html">How to Help FAQ</a></li> |
| <li><a href="/dev-mail.html">Development Lists</a></li> |
| <li><a href="/contributors/">Contributors Guide</a></li> |
| <li class="divider"></li> |
| <li><a href="/submitting-patches.html">Submitting patches</a></li> |
| <li><a href="/builds.html">Source Code and Builds</a></li> |
| <li><a href="/coding-standards.html">Coding standards</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Contributors+Guide">Contributors Guide</a></li> |
| <li class="divider"></li> |
| <li><a href="/release-guidelines.html">Release Guidelines</a></li> |
| <li><a href="/bylaws.html">PMC Charter</a></li> |
| <li><a href="/volunteers.html">Volunteers</a></li> |
| <li><a href="https://gitbox.apache.org/repos/asf?p=struts.git">Source Repository</a></li> |
| <li><a href="/updating-website.html">Updating the website</a></li> |
| </ul> |
| </li> |
| <li class="apache"><a href="http://www.apache.org/"><img src="/img/apache.png"></a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </nav> |
| </header> |
| |
| |
| <article class="container"> |
| <section class="col-md-12"> |
| <a class="edit-on-gh" href="https://github.com/apache/struts-site/edit/master/source/maven-archetypes/index.md" title="Edit this page on GitHub">Edit on GitHub</a> |
| |
| <h1 class="no_toc" id="struts-2-maven-archetypes">Struts 2 Maven Archetypes</h1> |
| |
| <p>Struts 2 provides several <a href="http://maven.apache.org/">Maven</a> archetypes that create a starting point for our own applications.</p> |
| |
| <p><strong>Contents</strong></p> |
| |
| <ul id="markdown-toc"> |
| <li><a href="#quickstart" id="markdown-toc-quickstart">Quickstart</a></li> |
| <li><a href="#available-archetypes" id="markdown-toc-available-archetypes">Available Archetypes</a> <ul> |
| <li><a href="#the-blank-convention-archetype-struts2-archetype-convention" id="markdown-toc-the-blank-convention-archetype-struts2-archetype-convention">The Blank Convention Archetype (struts2-archetype-convention)</a> <ul> |
| <li><a href="#features" id="markdown-toc-features">Features</a></li> |
| </ul> |
| </li> |
| <li><a href="#the-blank-archetype-struts2-archetype-blank" id="markdown-toc-the-blank-archetype-struts2-archetype-blank">The Blank Archetype (struts2-archetype-blank)</a></li> |
| <li><a href="#the-starter-archetype-struts2-archetype-starter" id="markdown-toc-the-starter-archetype-struts2-archetype-starter">The Starter Archetype (struts2-archetype-starter)</a> <ul> |
| <li><a href="#features-1" id="markdown-toc-features-1">Features</a></li> |
| </ul> |
| </li> |
| <li><a href="#the-angularjs-archetype-struts2-archetype-angularjs" id="markdown-toc-the-angularjs-archetype-struts2-archetype-angularjs">The AngularJS Archetype (struts2-archetype-angularjs)</a> <ul> |
| <li><a href="#features-2" id="markdown-toc-features-2">Features</a></li> |
| </ul> |
| </li> |
| <li><a href="#the-portlet-blank-archetype-struts2-archetype-portlet" id="markdown-toc-the-portlet-blank-archetype-struts2-archetype-portlet">The Portlet Blank Archetype (struts2-archetype-portlet)</a> <ul> |
| <li><a href="#features-3" id="markdown-toc-features-3">Features</a></li> |
| </ul> |
| </li> |
| <li><a href="#the-portlet-database-archetype-struts2-archetype-dbportlet" id="markdown-toc-the-portlet-database-archetype-struts2-archetype-dbportlet">The Portlet Database Archetype (struts2-archetype-dbportlet)</a> <ul> |
| <li><a href="#features-4" id="markdown-toc-features-4">Features</a></li> |
| </ul> |
| </li> |
| <li><a href="#the-plugin-archetype-struts2-archetype-plugin" id="markdown-toc-the-plugin-archetype-struts2-archetype-plugin">The Plugin Archetype (struts2-archetype-plugin)</a> <ul> |
| <li><a href="#features-5" id="markdown-toc-features-5">Features</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li><a href="#creating-an-application-using-a-maven-archetype" id="markdown-toc-creating-an-application-using-a-maven-archetype">Creating an Application Using a Maven Archetype</a> <ul> |
| <li><a href="#staging-repository" id="markdown-toc-staging-repository">Staging repository</a></li> |
| <li><a href="#archetype-parameters" id="markdown-toc-archetype-parameters">Archetype Parameters</a></li> |
| </ul> |
| </li> |
| <li><a href="#command-quick-reference" id="markdown-toc-command-quick-reference">Command Quick Reference</a></li> |
| </ul> |
| |
| <h2 id="quickstart">Quickstart</h2> |
| |
| <p>A recommended way to start with Struts2 archetypes is to use <code class="highlighter-rouge">archetype:generate</code> goal with <code class="highlighter-rouge">filter</code> parameter.</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -Dfilter=org.apache:struts |
| </code></pre></div></div> |
| |
| <h2 id="available-archetypes">Available Archetypes</h2> |
| |
| <h3 id="the-blank-convention-archetype-struts2-archetype-convention">The Blank Convention Archetype (struts2-archetype-convention)</h3> |
| |
| <h4 id="features">Features</h4> |
| |
| <ul> |
| <li> |
| <p>Convention-based validation</p> |
| </li> |
| <li> |
| <p>Example actions</p> |
| </li> |
| <li> |
| <p>Package-level resource bundle</p> |
| </li> |
| <li> |
| <p>Unit-testing</p> |
| </li> |
| <li> |
| <p>Google AppEgine aware</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-convention |
| </code></pre></div></div> |
| |
| <h3 id="the-blank-archetype-struts2-archetype-blank">The Blank Archetype (struts2-archetype-blank)</h3> |
| |
| <p>See the <a href="struts2-archetype-blank.html">Struts 2 Blank Archetype</a> page for more information, including some basic Maven information, how to build and run the app, and basic application information.</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-blank |
| </code></pre></div></div> |
| |
| <h3 id="the-starter-archetype-struts2-archetype-starter">The Starter Archetype (struts2-archetype-starter)</h3> |
| |
| <p>The Starter archetype creates a more featured application using several common technologies used in production applications.</p> |
| |
| <h4 id="features-1">Features</h4> |
| |
| <ul> |
| <li> |
| <p>Sitemesh integration</p> |
| </li> |
| <li> |
| <p>Action example (instantiated both through Spring and Struts)</p> |
| </li> |
| <li> |
| <p>Spring integration</p> |
| </li> |
| <li> |
| <p>Validation example (action and action-alias level)</p> |
| </li> |
| <li> |
| <p>Conversion example (global and action level)</p> |
| </li> |
| <li> |
| <p>Resource bundle (both global, action and package level)</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-starter |
| </code></pre></div></div> |
| |
| <h3 id="the-angularjs-archetype-struts2-archetype-angularjs">The AngularJS Archetype (struts2-archetype-angularjs)</h3> |
| |
| <h4 id="features-2">Features</h4> |
| |
| <ul> |
| <li> |
| <p>Convention-based Action Configuration</p> |
| </li> |
| <li> |
| <p>Example actions with JSON Result</p> |
| </li> |
| <li> |
| <p>Example for AngularJS and Struts2 Integration</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-angularjs |
| </code></pre></div></div> |
| |
| <h3 id="the-portlet-blank-archetype-struts2-archetype-portlet">The Portlet Blank Archetype (struts2-archetype-portlet)</h3> |
| |
| <p>The Portlet blank archetype creates a minimally populated JSR 168 portlet.</p> |
| |
| <h4 id="features-3">Features</h4> |
| |
| <ul> |
| <li> |
| <p>View, Edit, and Help mode examples</p> |
| </li> |
| <li> |
| <p>Simple form for preferences in Edit mode</p> |
| </li> |
| <li> |
| <p>Can be deployed as a servlet or portlet application</p> |
| </li> |
| <li> |
| <p>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)</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-portlet |
| </code></pre></div></div> |
| |
| <h3 id="the-portlet-database-archetype-struts2-archetype-dbportlet">The Portlet Database Archetype (struts2-archetype-dbportlet)</h3> |
| |
| <p>The Portlet database archetype creates a simple JSR 168 portlet that displays the contents of a database table.</p> |
| |
| <h4 id="features-4">Features</h4> |
| |
| <ul> |
| <li> |
| <p>Uses Spring and Hsql to show a real database query</p> |
| </li> |
| <li> |
| <p>Builtin caching of query results</p> |
| </li> |
| <li> |
| <p>View, Edit, and Help mode examples</p> |
| </li> |
| <li> |
| <p>Simple form for preferences in Edit mode</p> |
| </li> |
| <li> |
| <p>Can be deployed as a servlet or portlet application</p> |
| </li> |
| <li> |
| <p>Can use Maven Jetty plugin to deploy as a servlet webapp</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myWebApp \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-dbportlet |
| </code></pre></div></div> |
| |
| <h3 id="the-plugin-archetype-struts2-archetype-plugin">The Plugin Archetype (struts2-archetype-plugin)</h3> |
| |
| <h4 id="features-5">Features</h4> |
| |
| <ul> |
| <li> |
| <p>Example new result type</p> |
| </li> |
| <li> |
| <p>Example XML-based configuration</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B -DgroupId=com.mycompany.mysystem \ |
| -DartifactId=myPlugin \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-plugin |
| </code></pre></div></div> |
| |
| <h2 id="creating-an-application-using-a-maven-archetype">Creating an Application Using a Maven Archetype</h2> |
| |
| <p>Run the following command from your new project’s parent directory. The project will be created in a sub-directory named after the <code class="highlighter-rouge">artifactId</code> parameter.</p> |
| |
| <p>The first two parameters, <code class="highlighter-rouge">groupId</code> and <code class="highlighter-rouge">artifactId</code>, should be set according to your needs:</p> |
| |
| <ul> |
| <li> |
| <p><code class="highlighter-rouge">groupId</code> This should be the root package of your application, e.g., com.mycompany.myapp.</p> |
| </li> |
| <li> |
| <p><code class="highlighter-rouge">artifactId</code> Names the project directory that will be created in the current directory.</p> |
| </li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B \ |
| -DgroupId=tutorial \ |
| -DartifactId=tutorial \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-blank |
| </code></pre></div></div> |
| |
| <h3 id="staging-repository">Staging repository</h3> |
| |
| <p>If the above command will fail because of missing archetypes in central repository, you can try to use staging repository.</p> |
| |
| <p>Add staging repository to your settings.xml</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code><settings> |
| <profiles> |
| <profile> |
| <id>staging</id> |
| <repositories> |
| <repository> |
| <id>archetype</id> |
| <url>https://repository.apache.org/content/repositories/snapshots/</url> |
| <releases> |
| <enabled>true</enabled> |
| <checksumPolicy>fail</checksumPolicy> |
| </releases> |
| <snapshots> |
| <enabled>true</enabled> |
| <checksumPolicy>warn</checksumPolicy> |
| </snapshots> |
| </repository> |
| </repositories> |
| </profile> |
| </profiles> |
| </settings> |
| </code></pre></div></div> |
| |
| <p>Use <code class="highlighter-rouge">staging</code> profile in the command.</p> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mvn archetype:generate -B \ |
| -DgroupId=tutorial \ |
| -DartifactId=tutorial \ |
| -DarchetypeGroupId=org.apache.struts \ |
| -DarchetypeArtifactId=struts2-archetype-blank \ |
| -Pstaging |
| </code></pre></div></div> |
| |
| <h3 id="archetype-parameters">Archetype Parameters</h3> |
| |
| <p>The <code class="highlighter-rouge">-B</code> option runs <code class="highlighter-rouge">archetype:generate</code> in batch mode; it avoids a prompt to confirm our settings.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>groupId</td> |
| <td>The id for the group the application belongs to. Usually is the root package for applications in your company, e.g. com.mycompany</td> |
| </tr> |
| <tr> |
| <td>artifactId</td> |
| <td>The id for the project. The project will be created a sub-directory named after this parameter.</td> |
| </tr> |
| <tr> |
| <td>archetypeGroupId</td> |
| <td>The group id of the archetype. Will always be org.apache.struts for Struts archetypes</td> |
| </tr> |
| <tr> |
| <td>archetypeArtifactId</td> |
| <td>The id of the archetype</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="command-quick-reference">Command Quick Reference</h2> |
| |
| <p>These commands are used from the directory created by the archetype plugin (the project’s sub-directory that was created in the previous step).</p> |
| |
| <ul> |
| <li>To install</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn install |
| </code></pre></div></div> |
| |
| <ul> |
| <li>To run test cases</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn test |
| </code></pre></div></div> |
| |
| <ul> |
| <li>To clean up (removes generated artifacts)</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn clean |
| </code></pre></div></div> |
| |
| <ul> |
| <li>To package (creates a WAR file)</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn package |
| </code></pre></div></div> |
| |
| <ul> |
| <li>To grab necessary JAR files etc.</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn initialize |
| </code></pre></div></div> |
| |
| <ul> |
| <li>To run it with Jetty</li> |
| </ul> |
| |
| <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn jetty:run |
| </code></pre></div></div> |
| |
| </section> |
| </article> |
| |
| |
| <footer class="container"> |
| <div class="col-md-12"> |
| Copyright © 2000-2018 <a href="http://www.apache.org/">The Apache Software Foundation </a>. |
| All Rights Reserved. |
| </div> |
| <div class="col-md-12"> |
| Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are |
| trademarks of The Apache Software Foundation. |
| </div> |
| <div class="col-md-12">Logo and website design donated by <a href="https://softwaremill.com/">SoftwareMill</a>.</div> |
| </footer> |
| |
| <script>!function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (!d.getElementById(id)) { |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//platform.twitter.com/widgets.js"; |
| fjs.parentNode.insertBefore(js, fjs); |
| } |
| }(document, "script", "twitter-wjs");</script> |
| <script src="https://apis.google.com/js/platform.js" async="async" defer="defer"></script> |
| |
| <div id="fb-root"></div> |
| |
| <script>(function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (d.getElementById(id)) return; |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; |
| fjs.parentNode.insertBefore(js, fjs); |
| }(document, 'script', 'facebook-jssdk'));</script> |
| |
| |
| </body> |
| </html> |