blob: db793993ece16f9013faafae8c39c4645995c786 [file] [log] [blame]
<!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="/css/syntax.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>
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
/* We explicitly disable cookie tracking to avoid privacy issues */
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '41']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<a href="https://github.com/apache/struts" class="github-ribbon">
<img decoding="async" loading="lazy" style="position: absolute; right: 0; border: 0;" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1">
</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-2024.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>
<li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy Policy</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><a href="/commercial-support.html">Commercial Support</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 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="/contributors/">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></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></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></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></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></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></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="language-plaintext highlighter-rouge">archetype:generate</code> goal with <code class="language-plaintext highlighter-rouge">filter</code> parameter.</p>
<div class="language-plaintext 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>Convention-based validation</li>
<li>Example actions</li>
<li>Package-level resource bundle</li>
<li>Unit-testing</li>
<li>Google AppEgine aware</li>
</ul>
<div class="language-plaintext 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">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="language-plaintext 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>
<p>-Sitemesh integration</p>
<ul>
<li>Action example (instantiated both through Spring and Struts)</li>
<li>Spring integration</li>
<li>Validation example (action and action-alias level)</li>
<li>Conversion example (global and action level)</li>
<li>Resource bundle (both global, action and package level)</li>
</ul>
<div class="language-plaintext 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>Convention-based Action Configuration</li>
<li>Example actions with JSON Result</li>
<li>Example for AngularJS and Struts2 Integration</li>
</ul>
<div class="language-plaintext 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>View, Edit, and Help mode examples</li>
<li>Simple form for preferences in Edit mode</li>
<li>Can be deployed as a servlet or portlet application</li>
<li>Can use Maven Jetty plugin to deploy with the pluto-embedded profile (usage ‘mvn jetty:run -Ppluto-embedded’,
-then access http://localhost:8080/&lt;artifactId&gt;/pluto/index.jsp)</li>
</ul>
<div class="language-plaintext 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>Uses Spring and Hsql to show a real database query</li>
<li>Builtin caching of query results</li>
<li>View, Edit, and Help mode examples</li>
<li>Simple form for preferences in Edit mode</li>
<li>Can be deployed as a servlet or portlet application</li>
<li>Can use Maven Jetty plugin to deploy as a servlet webapp</li>
</ul>
<div class="language-plaintext 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>Example new result type</li>
<li>Example XML-based configuration</li>
</ul>
<div class="language-plaintext 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="language-plaintext highlighter-rouge">artifactId</code> parameter.</p>
<p>The first two parameters, <code class="language-plaintext highlighter-rouge">groupId</code> and <code class="language-plaintext highlighter-rouge">artifactId</code>, should be set according to your needs:</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">groupId</code> This should be the root package of your application, e.g., com.mycompany.myapp.</li>
<li><code class="language-plaintext highlighter-rouge">artifactId</code> Names the project directory that will be created in the current directory.</li>
</ul>
<div class="language-plaintext 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="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;settings&gt;
&lt;profiles&gt;
&lt;profile&gt;
&lt;id&gt;staging&lt;/id&gt;
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;archetype&lt;/id&gt;
&lt;url&gt;https://repository.apache.org/content/repositories/snapshots/&lt;/url&gt;
&lt;releases&gt;
&lt;enabled&gt;true&lt;/enabled&gt;
&lt;checksumPolicy&gt;fail&lt;/checksumPolicy&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;true&lt;/enabled&gt;
&lt;checksumPolicy&gt;warn&lt;/checksumPolicy&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;/profile&gt;
&lt;/profiles&gt;
&lt;/settings&gt;
</code></pre></div></div>
<p>Use <code class="language-plaintext highlighter-rouge">staging</code> profile in the command.</p>
<div class="language-plaintext 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="language-plaintext highlighter-rouge">-B</code> option runs <code class="language-plaintext 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="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> mvn install
</code></pre></div></div>
<ul>
<li></li>
<li>To run test cases</li>
</ul>
<div class="language-plaintext 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="language-plaintext 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="language-plaintext 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="language-plaintext 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="language-plaintext 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 &copy; 2000-2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>.
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are
trademarks of The Apache Software Foundation. All Rights Reserved.
</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>