-
Notifications
You must be signed in to change notification settings - Fork 12
/
basic-javaee-app.html
305 lines (305 loc) · 18.8 KB
/
basic-javaee-app.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<html>
<head>
<meta charset="utf-8">
<title>Forge | Writing Basic Java EE App</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<style>
body {
padding-top: 60px;
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<link href="/images/favicon.ico" rel="icon">
<link href="/stylesheets/styles.css" rel="stylesheet" type="text/css">
<link href="/stylesheets/bootstrap-responsive.min.css" rel="stylesheet" type="text/css">
<link href="/stylesheets/prettify.css" rel="stylesheet" type="text/css">
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
<script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
<script src="/javascripts/bootstrap-collapse.js" type="text/javascript"></script>
<script src="/javascripts/prettify.js" type="text/javascript"></script>
<script src="/javascripts/videoscale.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$("pre.prettyprint code").removeClass("prettyprint").removeClass("linenums");
prettyPrint();
});
</script>
<script>
$(document).ready(function() {
var pathname = window.location.pathname;
console.log(pathname);
$("body > .navbar a[href='" + pathname + "']").closest("li").addClass("active");
$("body > #content ul.nav a[href='" + pathname + "#content']").closest("li").addClass("active");
});
</script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<div class="github-banner hidden-phone hidden-tablet">
<a href="https://github.com/forge/core">
<img alt="Fork me on GitHub" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" style="position:absolute;top:0;right:0;border:0;">
</a>
</div>
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/index.html">
<img alt="JBoss Forge" class="forge-logo" src="/images/jbossforge_icon_256px.png">
</a>
<div class="nav-collapse">
<ul class="nav">
<li>
<a href="/index.html">Home</a>
</li>
<li>
<a href="https://github.com/forge/core#jboss-forge-20">Forge 2</a>
</li>
<li>
<a href="/docs/index.html">Documentation</a>
</li>
<li>
<a href="/team.html">Team</a>
</li>
<li>
<a href="https://community.jboss.org/en/forge">Forums</a>
</li>
<li>
<a href="https://github.com/forge/core">Source</a>
</li>
<li>
<a href="/plugins.html">Plugins</a>
</li>
<li>
<a href="https://issues.jboss.org/browse/FORGE" target="issue tracker">Issue Tracker</a>
</li>
<li>
<a href="https://issues.jboss.org/browse/FORGE#selectedTab=com.atlassian.jira.plugin.system.project%3Aroadmap-panel" target="roadmap">Roadmap</a>
</li>
<li>
<a href="/events.html">Events</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container" id="content">
<div class="container">
<div class="row">
<div class="span3">
<ul class="nav nav-list">
<li class="nav-header">Using Forge</li>
<li>
<a href="/docs/using/#content">Installation</a>
</li>
<li>
<a href="/docs/using/installing-new-plugins.html#content">Installing new Plugins</a>
</li>
<li>
<a href="/docs/using/basic-javaee-app.html#content">Writing Basic Java EE App</a>
</li>
<li>
<a href="/docs/using/samples.html#content">Samples</a>
</li>
<li>
<a href="/docs/using/configure-proxy.html#content">Configure HTTP Proxy</a>
</li>
<li>
<a href="/docs/using/profiling-forge.html#content">Profiling Forge</a>
</li>
<li>
<a href="/docs/using/debugging-forge.html#content">Debugging Forge</a>
</li>
<li>
<a href="/docs/using/faq.html#content">FAQ</a>
</li>
<li>
<a href="/docs/using/affiliation.html#content">Affiliation</a>
</li>
<li class="nav-header">Get involved</li>
<li>
<a href="/docs/get_involved/contribute.html#content">Contribute or Get Involved</a>
</li>
<li>
<a href="/docs/get_involved/release-guide.html#content">Release Guide</a>
</li>
<li>
<a href="/docs/get_involved/write-docs.html#content">Improve our documentation</a>
</li>
<li class="nav-header">Important plugins</li>
<li>
<a href="/docs/important_plugins/arquillian-testing.html#content">Arquillian Testing</a>
</li>
<li>
<a href="/docs/important_plugins/ui-scaffolding.html#content">UI Scaffolding</a>
</li>
<li class="nav-header">Developing plugins</li>
<li>
<a href="/docs/plugin_development/#content">Developing a plugin</a>
</li>
<li>
<a href="/docs/plugin_development/reference-forge-api.html#content">Reference Forge API</a>
</li>
<li>
<a href="/docs/plugin_development/implement-plugin-interface.html#content">Implement the Plugin interface</a>
</li>
<li>
<a href="/docs/plugin_development/give-your-plugin-name.html#content">Give your Plugin a name</a>
</li>
<li>
<a href="/docs/plugin_development/add-commands-to-plugin.html#content">Add Commands to your Plugin</a>
</li>
<li>
<a href="/docs/plugin_development/add-options-to-command.html#content">Add Options to your Commands</a>
</li>
<li>
<a href="/docs/plugin_development/enable-piping.html#content">Enable Piping between Commands</a>
</li>
<li>
<a href="/docs/plugin_development/facets.html#content">Enable modular functionality with Facets</a>
</li>
<li>
<a href="/docs/plugin_development/test-plugins.html#content">Test your Plugin</a>
</li>
<li>
<a href="/docs/plugin_development/reference-libraries.html#content">Reference Libraries</a>
</li>
<li>
<a href="/docs/plugin_development/make-plugin-available.html#content">Make your Plugin available to Forge</a>
</li>
<li>
<a href="/docs/plugin_development/add-plugin-cpi.html#content">Add your Plugin to the Central Plugin Index</a>
</li>
<li>
<a href="/docs/plugin_development/important-apis.html#content">Important APIs</a>
</li>
<li>
<a href="/docs/plugin_development/configure-plugin-repo.html#content">Configure a plugin repository for Forge</a>
</li>
</ul>
</div>
<div class="span9">
<h1>Writing Basic Java EE Application</h1>
<p>For the most part, people interested in Forge are likely interested in creating web-applications. Thusly, this chapter will overview the basic steps to generate such an application using Forge.</p>
<h2>Get Started with Scaffolding</h2>
<p>Assuming you have already completed the steps to install Forge, the first thing you’ll need to do is download and install a Java EE application server, for example <a href="http://www.jboss.org/jbossas/downloads.html">JBoss Application Server 7</a>. This server will host your application once it is built.</p>
<p>Next, follow these steps to create your skeleton web-application; be sure to replace any {ARGS} with your own personal values. Also keep in mind that while typing commands, you may press <TAB> at any time to see command completion options:</p>
<h2>Start Forge</h2>
<p>Execute <code>forge</code> from a command prompt, or open your shortcut, if you created one during the installation process.</p>
<h2>Create a new project</h2>
<pre class="command"><code class="command">$ new-project --named {name} --topLevelPackage {com.example.project} --projectFolder {/directory/path}</code></pre>
<h2>Set up scaffolding</h2>
<p>Press <span class="caps">ENTER</span> to confirm installation of any required facet dependencies and/or packaging types. You should get these 3 questions: </p>
<div class="alert alert-info">We recommend using the latest stable (non-<span class="caps">SNAPSHOT</span>) versions of necessary libraries.</div>
<pre class="command"><code class="command">$ scaffold setup</code></pre>
<pre class="command"><code class="command">? No scaffold type was selected, use default [JavaServer Faces]? [Y/n]
? Scaffold provider [faces] is not installed. Install it? [Y/n] 
? Facet [forge.maven.WebResourceFacet] requires packaging type(s) [war], but is currently [jar]. Update packaging? (Note: this could deactivate other plugins in your project.) [Y/n] </code></pre>
<p>Press <span class="caps">ENTER</span> for those 3 questions. Next, we have:</p>
<pre class="command"><code class="command">Use which version of 'jboss-javaee-6.0' ?</code></pre>
<p>Again, press <span class="caps">ENTER</span> for the default value:</p>
<pre class="command"><code class="command">? Choose an option by typing the number of the selection [*-default] </code></pre>
<p>Keep on pressing <span class="caps">ENTER</span> to choose default values for the next questions:</p>
<pre class="command"><code class="command">? Create scaffold in which sub-directory of web-root? (e.g. http://localhost:8080/ForgeTest/DIR) [/]</code></pre>
<h2>Set up persistence (<span class="caps">JPA</span>)</h2>
<p>Press <span class="caps">ENTER</span> to confirm installation of any required facet dependencies and/or packaging types, and remember to press <span class="caps">TAB</span> if you are not sure what comes next.</p>
<pre class="command"><code class="command">$ persistence setup --provider {your JPA implementation} --container {your container}</code></pre>
<p>If you choose a Java EE container, press <span class="caps">ENTER</span> to answer default values for the next questions:</p>
<pre class="command"><code class="command">? Do you want to install a JPA 2 metamodel generator? [y/N]</code></pre>
<p>If you choose <span class="caps">HIBERNATE</span>:</p>
<pre class="command"><code class="command">? The JPA provider [HIBERNATE], also supplies extended APIs. Install these as well? [y/N]</code></pre>
<p>If you do not wish to use a Java EE container default data-source, you can also specify additional connection parameters such as <span class="caps">JNDI</span> data-source names, <span class="caps">JDBC</span> connection information, and data-source types. Note, however, that this means you will probably need configure your application server to provide this new data-source and/or database connection.</p>
<h2>Create some <span class="caps">JPA</span> entities:</h2>
<pre class="command"><code class="command">$ entity --named Customer</code></pre>
<p>At which point Forge will automatically pick-up the newly created entity, and will be ready to add fields. We refer to this as “holding” an entity, or “holding” a file.</p>
<pre class="command"><code class="command">Customer.java $ field string --named firstName
Customer.java $ field string --named lastName</code></pre>
<h3>While “holding” most files, you may inspect them using ‘ls’.</h3>
<pre class="command"><code class="command">Customer.java $ ls</code>

<code class="command">[fields]
private::String::firstName; private::String::lastName;
private::int::version; private::long::id;</code>

<code class="command">[methods]
public::getFirstName()::String public::getId()::long
public::getLastName()::String public::getVersion()::int
public::setFirstName(final String firstName)::void public::setId(final long id)::void
public::setLastName(final String lastName)::void public::setVersion(final int version)::void
public::toString()::String</code>

<code class="command">Customer.java $</code></pre>
<h3>Picking up other files</h3>
<p>As stated above, creating a new entity will automatically “pick-up” and “hold” that file. When a file is “held”, that file is the context that operations are performed in. To change that context and “pickup” another file, use the <code>pick-up</code> command.</p>
<p>Eg. <code>$ pick-up src/main/java/com/company/Client.java</code></p>
<h2>Generate some UI scaffolding!</h2>
<p>Once you have created fields in the entity, it’s time to generate some scaffolding. Since we have already installed our scaffold, this step is easy. While “holding” Customer.java, type:</p>
<pre class="command"><code class="command">Customer.java $ scaffold from-entity</code>

<code class="command">? No scaffold type was selected, use default (JSF)? [Y/n]
Wrote /src/main/java/com/scaffold/domain/Customer.java
Wrote /src/main/java/com/scaffold/view/CustomerBean.java
Wrote /src/main/webapp/scaffold/customer/view.xhtml
Wrote /src/main/webapp/scaffold/customer/create.xhtml
Wrote /src/main/webapp/scaffold/customer/list.xhtml
***SUCCESS*** Generated UI for [com.scaffold.domain.Customer]</code>

<code class="command">Customer.java $</code></pre>
<h2>That’s it! Now build your project and deploy it onto your Java EE Application Server of choice:</h2>
<pre class="command"><code class="command">$ build</code></pre>
<p>Or, to control the build more finely, you can also build your new project using native Maven commands. (If you do not have maven installed, Forge will use its provided embedded Maven support.)</p>
<pre class="command"><code class="command">$ mvn clean package</code></pre>
<h2>(Optional) Deploy/undeploy to AS7</h2>
<p>First you need to install the AS7 Forge Plugin by typing the following command:</p>
<pre class="command"><code class="command">$ forge install-plugin jboss-as-7</code></pre>
<p>Next, set up the plugin in your project:</p>
<pre class="command"><code class="command">$ as7 setup</code></pre>
<p>Then you will be able to deploy, redeploy, and un-deploy as desired using the following commands:</p>
<pre class="command"><code class="command">$ as7 deploy
$ as7 redeploy
$ as7 undeploy</code></pre>
<div class="alert alert-info">The server must be running.</div>
<h2>That’s it! Access your deployed application at:</h2>
<p><em>http://localhost:8080/<strong>projectname</strong></em></p>
</div>
</div>
</div>
<hr>
<footer>
<p>© JBoss 2014</p>
</footer>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-34467975-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script src="http://www.redhat.com/j/elqNow/elqCfg.js" type="text/javascript"></script>
<script src="http://www.redhat.com/j/elqNow/elqImg.js" type="text/javascript"></script>
<div id="oTags">
<script src="http://www.redhat.com/j/s_code.js" type="text/javascript"></script>
<script>
var coreUrl = encodeURI(document.URL.split("?")[0]);
var urlSplit = coreUrl.toLowerCase().split(/\//);
var urlLast = urlSplit[urlSplit.length-1];
var pageNameString = "";
var siteName = "";
var minorSectionIndex = 3
if (urlLast == "") {
urlSplit.splice(-1,1);
}
if (urlLast.search(/\./) >= 0) {
if (urlLast == "index.html") {
urlSplit.splice(-1,1);
}
else {
urlSplit[urlSplit.length-1] = urlLast.split(".").splice(0,1);
}
}
siteName = urlSplit[2].split(".")[1];
s.prop14 = s.eVar27 = siteName || "";
s.prop15 = s.eVar28 = urlSplit[minorSectionIndex] || "";
s.prop16 = s.eVar29 = urlSplit[minorSectionIndex+1] || "";
pageNameString = urlSplit.splice(3).join(" | ");
s.pageName = "jboss | community | " + siteName + " | " + pageNameString;
s.channel = "jboss | community";
s.prop4 = s.eVar23 = encodeURI(document.URL);
s.prop21 = s.eVar18 = coreUrl;
s.prop2 = s.eVar22 = "en";
s.prop3 = s.eVar19 = "us";
</script>
<script src="http://www.redhat.com/j/rh_omni_footer.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
</script>
<noscript>
<a href="http://www.omniture.com" title="Web Analytics">
<img alt="" border="0" height="1" src="https://smtrcs.redhat.com/b/ss/redhatcom,redhatglobal/1/H.25.4--NS/0?[AQB]&cdp=3&[AQE]" width="1">
</a>
</noscript>
</div>
</body>
</html>