Project

General

Profile

Sample-hello-world » History » Version 6

Henning Blohm, 28.02.2021 13:49

1 2 Henning Blohm
h1. Hello World Web App Sample
2
3
TBC
4
5
This sample application shows how to set up the most basic Java Web application in z2. 
6
7
Z2 integrates with the Jetty Web container and Web applications on Z2 are really just standard Java EE Web applications. What is unfamiliar for the typical Maven, Gradle, or Ant user is how applications are developed and modularized on Z2. So this sample case is hence more about Web applications as developed on Z2 than it is about Web application development.
8
9 4 Henning Blohm
Please skip to [[#Step by Step - Or Setting Things Up Yourself|Step by Step - Or Setting Things Up Yourself]] unless you just want to see it running.
10 3 Henning Blohm
11 2 Henning Blohm
This sample is stored in the repository "z2-samples-hello-world-web":https://redmine.z2-environment.net/projects/z2-samples/repository/z2-samples-hello-world-web.
12
13
h2. Prerequisites
14
15
{{include(Java_Version_Requirements)}}
16
17
h2. Setting up the sample
18
19
Follow these instructions, if you just want to see it running. Otherwise we recommend skipping this section and rather follow the step by step instructions below.
20
21
Here's the really fast version:
22
23
{{include(Install_sample_prefix)}}
24
25
<pre><code>
26
git clone -b v2.8 https://www.z2-environment.net/git/z2-samples-hello-world-web
27
</code></pre>
28
29
{{include(Install_sample_postfix)}}
30
31
The first time you launch the sample, it will take a while to download all required resources.
32
33
h2. Step by Step - Or Setting Things Up Yourself
34 5 Henning Blohm
35
36
In this section we will manually create the basic structure of a Z2 module and see how it is discovered by Z2 during development.
37
38
We assume that you have prepared some development workspace install and that you installed z2-base.core, the core runtime of z2 in that folder. If you have not done so yet, run
39
40
{{include(Install_sample_prefix)}}
41
42
h3. Create a Module
43
44
Change into install and create a folder z2-samples-hello-world-web and in that folder create the following structure
45
46
In this section we will manually create the basic structure of a Z2 module and see how it is discovered by Z2 during development.
47
48
We assume that you have prepared some development workspace install and that you installed z2-base.core, the core runtime of z2 in that folder. If you have not done so yet, run
49
50
{{include(Install_sample_prefix)}}
51
52
h3. Create a Module
53
54
Change into install and create a folder z2-samples-hello-world-web and in that folder create the following structure
55
56
In this section we will manually create the basic structure of a Z2 module and see how it is discovered by Z2 during development.
57
58
We assume that you have prepared some development workspace install and that you installed z2-base.core, the core runtime of z2 in that folder. If you have not done so yet, run
59
60
{{include(Install_sample_prefix)}}
61
62
h3. Create a Module
63
64
Change into install and create a folder z2-samples-hello-world-web and in that folder create the following structure
65
66
<pre>
67
├── java
68
│   ├── src.api
69
│   ├── src.impl
70
│   └── z.properties
71
└── web
72
    ├── WebContent
73
    │   └── WEB-INF
74
    │       └── web.xml
75
    └── z.properties
76
</pre>
77
78 6 Henning Blohm
where @java/z.properties@:
79
80
<pre><code class="java">
81
com.zfabrik.component.type=com.zfabrik.java
82
83
java.privateReferences=\
84
	com.zfabrik.servletjsp
85
</code></pre>
86
87
and @web/z.properties@:
88
89
<pre><code class="java">
90
com.zfabrik.component.type=com.zfabrik.ee.webapp
91
92
webapp.path=/hello-world
93
webapp.requiredPaths=
94
95
webapp.server=environment/webServer
96
com.zfabrik.systemStates.participation=environment/webWorkerUp
97
</code></pre>
98
99
and @web/WEB-INF/web.xml@:
100
101
<pre><code class="xml">
102
<?xml version="1.0" encoding="UTF-8"?>
103
104
<web-app id="z2WebApp" version="3.0"
105
	xmlns="http://java.sun.com/xml/ns/javaee"
106
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
107
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
108
</web-app>
109
</code></pre>
110
111
112
*Note:* If you are using the Eclipse IDE and have installed the eclipsoid plugin ([[How_to_install_Eclipsoid]]) you can use the wizard at "File > New > Other > New Java/Web z2-Project". Note however that it may be necessary to adapt the generated files to match the ones above (in particular check for @web.xml@ to refere to servlet api 3.0 at least).
113
114
This is the most essential module structure for a Web Application. You will find all Web Application resources directly under the web folder. Java resources however would be put into the java component folder, in src.impl if they are not to be re-used by (or "be visible to") other modules, in src.api, if they are not to be re-used by (and hence "not visible to") other modules.