Project

General

Profile

Getting Started » History » Version 22

Henning Blohm, 02.03.2015 09:44

1 3 Henning Blohm
h1. Getting Started with org.z2env
2 1 Henning Blohm
3
See also [[FAQ]]
4
5
To understand how z2 works, you need to understand at most what are z2 modules and components and what are component repositories and how these concepts interplay. 
6
7 17 Henning Blohm
Check out [[Getting Started#Understanding-Z2|Understanding Z2]] for that.
8 1 Henning Blohm
9
It is simplest to start by running a simple Java main program in z2 or a simple Web App. 
10
11
Follow this trail:
12
13
* [[Getting Started#Building-z2env-core|Building the core]]
14
* [[Getting Started#Running-a-Hello-World-main-program|Running a Hello World main program]]
15
* [[Getting Started#Running-a-Hello-World-Web-App|Running a Hello World Web App]]
16
* [[Getting Started#Developing-with-Eclipse-or-IntelliJ|Developing with Eclipse or IntelliJ]]
17
* [[Getting Started#Going-Multi-Module|Going Multi Module]]
18 14 Henning Blohm
* [[Getting Started#Going-System-Centric|Going System Centric]]
19 18 Henning Blohm
* [[Getting Started#Understanding-the-<HOME>|Understanding the <HOME>]]
20
* [[Getting Started#Understanding-Z2|Understanding Z2]]
21 1 Henning Blohm
22 9 Henning Blohm
---
23 1 Henning Blohm
24
h2. Building z2env-core
25
26
(For now, we need to build the core).
27
28 4 Henning Blohm
{{collapse
29 1 Henning Blohm
h3. Pre-requisites
30
31
* You need Git installed
32
* You need a JDK, at least version 7
33
* You need the ANT build tool
34
35
First clone http://git.z2-environment.net/z2env.core
36
37
<pre>
38
git clone http://git.z2-environment.net/z2env.core
39
</pre>
40
41 20 Henning Blohm
Change into *z2env.core/org.z2env.core.main* and run 
42 1 Henning Blohm
43
<pre>
44
ant -Doutput=<z2home> -Dsetup=<setup> 
45
</pre>
46
47
where <z2home> is where you want to install z2 (the *z2 home* that is) and <setup> is a choice of pre-configured content, actually component repositories.
48
49 19 Henning Blohm
If you omit *output* it will default to *gen/dist*. If you omit *setup*, no content will be pre-configured. 
50 1 Henning Blohm
51
Check the folder *setups* for available setups of the core build. These can be local (all repos will be cloned locally) or remote (repos will be remoted).
52
53
In general this build always updates only boot, z.jar, roots. It will not remove anything.
54
55
Example to install/update a core only into ../../z2env:
56
57
<pre>
58
ant -Doutput=../../z2env 
59
</pre>
60
61
To install/update a web-basic setup (with tomcat and eclipsoid support) with updates from remote repos:
62
63
<pre>
64
ant -Doutput=../../z2env -Dsetup=web-basic-remote
65
</pre>
66 19 Henning Blohm
67 22 Henning Blohm
and this is what we would like you to do for now. 
68 1 Henning Blohm
69
Check out [[wiki#Understanding-the-ltHOMEgt|Understanding the <HOME>]] to learn more about the generated structure.
70
71 2 Henning Blohm
h4. Summary
72 1 Henning Blohm
73 2 Henning Blohm
* At any time you can update a z2 core installation by running the core build and using the *output* property to point to your installation
74
* Using the *setup* property you can choose between completely local setups (no remote access required - no automatic synchronization from remote either) or mostly remote setups (all except the core will be synchronized from remote repositories). 
75
76 4 Henning Blohm
}}
77
78 9 Henning Blohm
79
---
80
81 1 Henning Blohm
h2. Running a Hello World main program
82
83 5 Henning Blohm
In this section we will let z2 do what it is actually made for: Run some Java program in a modular environment without build and deploy.
84
85 4 Henning Blohm
{{collapse
86 21 Henning Blohm
For now, we will assume you have a z2 core installed in <HOME>. If you built the core as outlined above than <HOME> is the folder *z2env* next to your core clone.
87
88
In its purest form, all the core can actually execute is simple Java main programs. 
89 1 Henning Blohm
90
Being in a modular environment, even if we only want to say „Hello World“, we need a module. Let's call it the greeter module. In order to have a main program run by z2, we need to also declare a  component for it, as that is what we tell z2 to run (not a class – mind you – but rather a component in a module). Assuming we use the local component name hello, than the absolut component name is 
91
92
<pre>
93
greeter/hello
94
</pre>
95
96
Finally, as this component actually has implementation code, we need to declare a Java component. By convention this is 
97
98
<pre>
99
greeter/java
100
</pre>
101
102
Now, after installing in <HOME> the place to simply drop a module is under <HOME>/modules. You might need to create that folder.
103
104
All in all, here is the complete structure to create:
105
106
| <HOME>/modules/greeter/hello.properties | 
107
<pre><code class="ruby">org.z2env.component.type=org.z2env.main
108
component.className=greetings.Main
109
</code></pre> |
110
| <HOME>/modules/greeter/java/z.properties | 
111
<pre><code class="ruby">org.z2env.component.type=org.z2env.java
112
</code></pre> |
113
| <HOME>/modules/greeter/java/src.impl/greetings/Main.java |
114
<pre><code class="java">
115
package greetings;
116
117
public class Main {
118
  public static void main(String[] args) {
119
    System.out.println("Hello!");
120
  }
121
}
122
</code></pre> |
123
124
That gives us the two components of module greeter. To run this on the command line, run
125
126
<pre>
127
java -DcomponentName=greeter/hello -jar z.jar
128
</pre>
129
130
Now, obviously this sample is not worth a modular execution environment. But even from here, you could check your module in with some Git repository that is referenced from the roots and all other users of the same repo would be able to run your component without installing anything.
131
132 2 Henning Blohm
h4. Summary
133
134
* Running a simple program in a modular environment requires no more than declaring the modules and add some code
135
* Apart from more technical component types, at the heart of the z2 core is to run simple Java main programs
136
137 4 Henning Blohm
}}
138 2 Henning Blohm
139 9 Henning Blohm
140
---
141
142 1 Henning Blohm
h2. Running a Hello World Web App
143
144 6 Henning Blohm
Rather than just running a Main program, using the Tomcat add-on we might as well run full-featured Web applications - of course: From anywhere, without build and deploy.
145
146 4 Henning Blohm
{{collapse
147
148 1 Henning Blohm
This introduction explains how to connect a z2 core to a given Tomcat installation and how to develop a simple Web Application.
149
150
Furthermore it describes how to use the Dev Repository and the Eclipsoid plugin for the Eclipse or the IntelliJ development environment.
151
152
h3. Pre-Requisites
153
154
* We assume a development workspace in *workspace*.
155
* Have a local Tomcat (7 or higher) installation.*
156
157
h3. Steps we are going to take
158
159
# Create a module with a simple Web app
160
# Make it visible to Z2
161
# Run the Web App in a Tomcat Web Container
162
163
At first get yourself a z2env core with the *web-basic-local* or *web-basic-remote* setup. Make sure it is in your *workspace*. If you follow [[wiki#Building-z2env-core|Building the core]] this means running 
164
165
<pre>
166
ant -Doutput=workspace/z2env -Dsetup=web-basic-remote
167
</pre>
168
169
(*Note:* If in doubt, use an absolute path for *workspace*)
170
171
Using your IDE create a new project *hello* in *workspace* with the following structure:
172
173
| java/z.properties | 
174
<pre><code class="ruby">
175
org.z2env.component.type=org.z2env.java
176
java.privateReferences=\
177
	javax.servlet
178
</code></pre> |
179
| web/z.properties |
180
<pre><code class="ruby">
181
org.z2env.component.type=org.z2env.tomcat.webapp
182
webapp.path=/hello
183
</code></pre> |
184
| web/WebContent/index.jsp |
185
<pre><code class="html"><html><body>Hello! Did you know that 7*7=<%=7*7%>?</body></html></code></pre> |
186
| LOCAL | <empty file> |
187
188
Your *workspace* folder now contains two subfolders *z2env* and *hello*.
189
190
So far, that's it.  We will touch on the LOCAL file later. 
191
192
When we run Z2 knowing this Web Application, it will attempt to start a Tomcat Web Container that will serve the application's content. To do that, it needs to find one. 
193
194
In order to tell Z2 where to look, you can either set an environment variable *CATALINA_HOME* (you might have already – it's the Tomcat standard) or specify an environment variable *catalina.home*. 
195
196
To be on the safe side and assuming the location is */home/me/tomcat*, we open a terminal, change into *workspace/z2env* and run
197
198
<pre>
199
java -Dcatalina.home=/home/me/tomcat -jar z.jar hello/web
200
</pre>
201
202
Note, unlike for the main program, the command line will not return. Instead you can enter „q“ to quit or „s“ to synchronize. But first let's open a browser and check out 
203
204
<pre>
205
http://localhost:8080/hello
206
</pre>
207
208
*Note:* What you just created is a prototypical z2 module structure containing a Java component *java* (holding implementation) and a Web component *web*. 
209
210
Instead of creating the structure yourself, you could use the Eclipsoid plugin (introduced below) for that:
211
* In Eclipse: New / Others / new z2...., 
212
* In IntelliJ: New / Module / z2....
213
214
... but beware of the pre-generated configuration. Where it says *com.zfabrik* change to *org.z2env*.
215
216
217
*Note:* Now on to that LOCAL file. Unlike for the Hello World main program, this time it was to so-called Dev Repo that made our module available to z2. 
218
219
The dev repo is a key component to the development approach with z2. It checks for all modules that have a LOCAL file and that are stored some levels deep, relative to the parent folder of the z2 home (by default), which not so coincidentally is our workspace.
220
221
We call modules with a LOCAL file _armed_.
222
223
*Note:* By default the dev repo looks for modules beneath the parent folder of the <home> location. Use the system property *org.z2env.dev.local.workspace* to specify other locations (separated by comma) to check for modules.
224
225
226
Try this: 
227
228
# Remove LOCAL
229
# Enter „s“ for synchronization. 
230
# Check the URL above (should say „not found“)
231
# Create a LOCAL file again
232
# Synchronize
233
# Check again.
234
235
Similarly, from now on, changes made to the hello module will be picked up, whenever you synchronize.
236
237 2 Henning Blohm
h4. Summary
238
239
* Addons extend z2 with capabilities, such as a Tomcat hosted Web application (albeit running in z2's module environment)
240
* The _dev repository_ allows to flexibly define local modules. Modules can put into or out visibility by a simple LOCAL marker file.
241
242 4 Henning Blohm
}}
243
244 9 Henning Blohm
245
---
246
247 1 Henning Blohm
h2. Developing with Eclipse or IntelliJ
248
249
In this section we will add some code to the hello Web app and see how to develop using an integrated development environment like the Eclipse IDE or Jetbrains' IntelliJ IDEA.
250
251 4 Henning Blohm
{{collapse
252
253 1 Henning Blohm
h3. Pre-Requisite
254
255
* Have an Eclipse or IntelliJ installation
256
* Install the Eclipsoid plugin from http://z2-environment.net/eclipsoid/update/site.xml or by searching for "z2" in the IntelliJ Plugin Repository respectively
257
258
h3. Steps we are going to take
259
260
# Complete the development workspace setup
261
# Add a simple Controller
262
263
h4. In Eclipse
264
265
Use the workspace *workspace*. Create a Java project *hello* where we created the *hello* module. That is, we use the existing module as project content. You should now have an Eclipse development workspace that has one Java project named "hello". Right-click on the project and choose "Transform into z2 Project". A small "Z" icon should not decorate the project icon. 
266
267
Add a source folder *java/src.impl* to the project.
268
269
Try "Arm Z2 Projects" and "Disarm Z2 Projects" from the context menu. You should see a LOCAL file showing up and disappearing as well as the "Z" decoration showing a green halo and going back to normal. 
270
271
Go into Window/Preferences, pick "z2-Environment". Change the port to 8081, set the user to "z*" and the password to "z". Done.
272
273
h4. In IntelliJ
274
275
Add a source folder *java/src.impl* to the module.
276
277
Start a new Project with root folder *workspace*. Press the "Manage z2-Modules" button in the toolbar. Import the *hello* module into your IntelliJ project. Open the Settings dialog, pick "z2-Environment". Change the port to 8081, set the user to "z*" and the password to "z". Done.
278
279
h4. Independently of whether you use IntelliJ or Eclipse
280
281
Start z2 as in the previous section but make sure the development support is enabled. Use this command line:
282
283
<pre>
284
java -Dcatalina.home=/home/me/tomcat -jar z.jar org.z2env.dev.shared/ready hello/web
285
</pre>
286
287
(possibly you want to turn this into a shell script)
288
289
*Note:* The _system state_ *org.z2env.dev.shared/ready* will pull up all necessary development support components. Make sure this is part of your to-be-run list.
290
291
292
Regardless whether you are using Eclipse or IntelliJ, press the "Resolve Classpath from Z2" button in the toolbar. This will make sure that all required dependencies for Z2 modules, as far as Java code is concerned, will be resolved for your workspace. 
293
294
Now add a class *SimpleController* and change the following files:
295
296
| java/src.impl/hello/SimpleController.java | 
297
<pre><code class="java">
298
package hello;
299
300 11 Henning Blohm
import goodbye.GoodbyeService;
301
302 1 Henning Blohm
import java.io.IOException;
303
304 11 Henning Blohm
import javax.servlet.ServletException;
305
import javax.servlet.annotation.WebServlet;
306
import javax.servlet.http.HttpServlet;
307
import javax.servlet.http.HttpServletRequest;
308
import javax.servlet.http.HttpServletResponse;
309 1 Henning Blohm
310 11 Henning Blohm
import org.z2env.components.IComponentsLookup;
311
312
@WebServlet(urlPatterns="/do")
313
public class SimpleController extends HttpServlet {
314 13 Henning Blohm
    private static final long serialVersionUID = 1L;
315
316
    @Override
317
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
318
        GoodbyeService gb = IComponentsLookup.CL.lookup("goodbye/service", GoodbyeService.class);
319
        String input = req.getParameter("input");
320 1 Henning Blohm
        if (input!=null && input.trim().length()>0) {
321 11 Henning Blohm
            req.setAttribute(
322
                "output",
323 12 Henning Blohm
                "Hello "+input
324 11 Henning Blohm
            );
325
            req.setAttribute("input",input);
326 1 Henning Blohm
        }
327
        req.getRequestDispatcher("/").forward(req,resp);
328
    }
329 16 Henning Blohm
}</code></pre> |
330 1 Henning Blohm
| java/z.properties | 
331
<pre><code class="ruby">
332
org.z2env.component.type = org.z2env.java
333
334
java.privateReferences=\
335
  javax.servlet,\
336
  javax.servlet.jsp.jstl
337
</code></pre> |
338
| web/WebContent/index.jsp |
339
<pre><code class="html">
340
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
341
<html>
342
<body>
343
  <c:if test="${not empty output}">
344
    <p><c:out value="${output}"/></p>
345
  </c:if>
346
  <form method="POST" action="<c:url value='/do'/>">
347
    Input: <input type="text" name="input"><input type="submit" value="go!">
348
  </form>
349
</body>
350
</html>
351
</code></pre>|
352
353
Make sure the *hello* module is armed (right-click) by having a LOCAL file.
354
355
Now synchronize your running z2 by either:
356
357
* Pressing the "Sync with z2-Environment" button in the toolbar
358
* Pressing ALT+y in your IDE
359
* Entering "s" on the command line running z2.
360
361
Go to http://localhost:8080/hello and check it out.
362
363 2 Henning Blohm
h4. Summary
364 1 Henning Blohm
365 2 Henning Blohm
* Using IDE plugins for Eclipse or IntelliJ you can conveniently develop for Z2.
366
* Regardless of the component types in use, all class path considerations will be resolved from Z2 and you will never need to change IDE configuration.
367
* Using the interplay of IDE plugin and the dev repository (see also [[FAQ#Development]]) synchronization from the IDE and overlay of modules with local development versions is simple and fast. 
368
369 4 Henning Blohm
}}
370
371 9 Henning Blohm
372
---
373
374 1 Henning Blohm
h2. Going Multi-Module
375
376
In this section we will extend the previous work by a simple service module. 
377
378 4 Henning Blohm
{{collapse
379 1 Henning Blohm
h3. Pre-Requisites
380
381
# Have all the results from the previous section ready.
382
# Start IDE and z2 as above.
383
384
385
h3. Steps we are going to take
386
387
# add a new module with a service API
388
# reference the module API from the *hello* module and invoke the service.
389
390
391
In your workspace, use Eclipsoid to create a new z2 Java module *goodbye*. Open *java/z.properties* and change all *com.zfabrik.* prefixes to *org.z2env*. Essentially the file only needs the line
392
393
<pre><code class="ruby">
394
org.z2env.component.type=org.z2env.java
395
</code></pre>
396
397
In our API we will only expose an interface and rather leave the implementation hidden in the implementation parts of the module. We do that, as we prefer a strong separation of API and implementation. This is not at all required but a conscious design choice. 
398
399
400
| java/src.api/goodbye/GoodbyeService.java | 
401
<pre><code class="java">
402
package goodbye;
403
404
public interface GoodbyeService {
405
406
	String sayGoodbye(String in);
407
	
408
}
409
410
</code></pre> |
411
| java/src.impl/goodbye/GoodbyeServiceImpl.java | 
412
<pre><code class="java">
413
package goodbye;
414
415
public class GoodbyeServiceImpl implements GoodbyeService {
416
417
	@Override
418
	public String sayGoodbye(String in) {
419
		return "Goodbye "+in+"!";
420
	}
421
422
}
423
</code></pre> |
424 10 Henning Blohm
| service.properties | 
425 1 Henning Blohm
<pre><code class="ruby">
426
org.z2env.component.type=org.z2env.any
427
component.className=goodbye.GoodbyeServiceImpl
428
</code></pre> |
429
| java/z.properties | 
430
<pre><code class="ruby">
431
org.z2env.component.type=org.z2env.java
432
</code></pre> |
433
434
In effect we created the following:
435
436
* A module *goodbye* that has 
437
* A Java component with API and Implementation source code
438
* An _any_ component *goodbye/service* that manages the service implementation (as we will see below)
439
440
Back in the *hello* module, we want to use the _goodbye service_. We apply the following changes:
441
442
| java/z.properties | 
443
<pre><code class="ruby">
444
org.z2env.component.type=org.z2env.java
445
446
java.privateReferences=\
447
    javax.servlet,\
448
    javax.servlet.jsp.jstl,\
449
    goodbye
450
</code></pre> |
451
| java/src.impl/hello/SimpleController.java | 
452
<pre><code class="java">
453
package hello;
454
455
import goodbye.GoodbyeService;
456
457
import java.io.IOException;
458
459
import javax.servlet.ServletException;
460 13 Henning Blohm
import javax.servlet.annotation.WebServlet;
461 1 Henning Blohm
import javax.servlet.http.HttpServlet;
462
import javax.servlet.http.HttpServletRequest;
463
import javax.servlet.http.HttpServletResponse;
464
465
import org.z2env.components.IComponentsLookup;
466
467 13 Henning Blohm
@WebServlet(urlPatterns="/do")
468 1 Henning Blohm
public class SimpleController extends HttpServlet {
469 13 Henning Blohm
    private static final long serialVersionUID = 1L;
470 1 Henning Blohm
471
    @Override
472
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
473 13 Henning Blohm
        GoodbyeService gb = IComponentsLookup.CL.lookup("goodbye/service", GoodbyeService.class);
474 1 Henning Blohm
        String input = req.getParameter("input");
475
        if (input!=null && input.trim().length()>0) {
476
            req.setAttribute(
477 13 Henning Blohm
                "output",
478
                gb.sayGoodbye(input)
479
            );
480
            req.setAttribute("input",input);
481 1 Henning Blohm
        }
482
        req.getRequestDispatcher("/").forward(req,resp);
483
    }
484
}
485
</code></pre> |
486
487
After you have changed the Java references in *java/z.properties* you might want to press Alt-R or the "Resolve Classpath from Z2" button in the toolbar to have the IDE resolve the dependency for the *goodbye* module and so that
488
your IDE will not complain about using the *GoodbyeService* interface.
489
490
Now synchronize your running z2 by either:
491
492
* Pressing the "Sync with z2-Environment" button in the toolbar
493
* Pressing ALT+y in your IDE
494
* Entering "s" on the command line running z2.
495
496
Go to http://localhost:8080/hello and check it out.
497
498
h3. Discussion
499
500
What you just implemented is a programmatic component lookup. The first time <code>IComponentsLookup.CL.lookup("goodbye/service", GoodbyeService.class)</code> was invoked, z2 searched for a factory for *org.z2env.any* components. This specific factory simply created a singleton instance of the Goodbye Service and checked whether the requested interface is implemented. As that held, it returned the actual instance.
501
502
In later sections (for now check out [[z2-environment:How_to_Spring]]) we will explain how to that extends to the Spring Framework and Dependency Injection in general.
503 2 Henning Blohm
504
h4. Summary
505
506
* Being a modular runtime environment, Z2 offers an effective yet simple Java modularization approach
507
* The module concept of Z2 goes beyond code considerations and includes arbitrary component types such as Web applications
508 1 Henning Blohm
509
Feel free to apply changes to the Goodbye Service implementation class and have them made effective by synchronizing Z2.
510 4 Henning Blohm
511
}}
512 8 Henning Blohm
513 1 Henning Blohm
514 9 Henning Blohm
---
515
516 1 Henning Blohm
h2. Going System-Centric
517 2 Henning Blohm
518
In this section we show how to turn your z2 installation into a mere execution node of a system (which is what it really should be). That is, in team development situations for systems of non-trivial size of distribution requirements, it is crucial to be integrated with a common source code level. 
519 1 Henning Blohm
520 4 Henning Blohm
{{collapse
521
522 2 Henning Blohm
Using remote repositories in combination with the dev repository, z2 offers just that: Integration for all but those pieces you do actually need isolation from changes.
523
524
Using z2's synchronization approach rolling out changes to remote installation and scale-outs become a non-issue.
525 8 Henning Blohm
526
h3. Pre-Requisites
527
528
# Have the multi-module setup from the previous section at hand
529
# Start IDE and z2 as above.
530
531 2 Henning Blohm
532
h3. Steps we are going to take
533
534
# check our modules in with some new Git repository
535
# add a Git-based component repository component 
536
# develop with partial overlays
537
538
539 1 Henning Blohm
540 4 Henning Blohm
}}
541 1 Henning Blohm
542 9 Henning Blohm
543
544
---
545 1 Henning Blohm
546
h2. Understanding the <HOME>
547
548 4 Henning Blohm
We call an installation of a z2env core a *<home>*. The file structure of the *<home>* consists of few but important locations.
549 1 Henning Blohm
550 4 Henning Blohm
{{collapse
551 1 Henning Blohm
h3. Layout
552
553
| z.jar | The actual core implementation. This is precompiled.|
554
| boot/ | A component repository adding to the core and provides the most basic capabilities such as compiling Java code and running a main program. |
555
| roots/ | A file system component repository that is always registered by the core. This is typically filled with other repository components linking to remote or local component repositories. |
556
| modules/ | A file system repository declared under roots/ that is useful to locally augment a core installation.|
557
558
We use the modules repository for example for command line experiments and simple hacks. It is not as useful for regular development operations as is the dev repo.
559
560 4 Henning Blohm
561 1 Henning Blohm
h3. Folders and Properties
562
563
When running z2 from the command line, some logic is applied to derive where stuff is and some defaults apply:
564
565
|_. What |_. System property |_. Defaults |
566
| Z2 home - the installation location | org.z2env.home | If no system property is set, the environment variable Z2_HOME will be checked. If that is not set, the z2 home location will be derived from the location of the z.jar file |
567
| Dev Repo workspaces - where the Dev Repo checks for local modules | org.z2env.dev.local.workspaces | Defaults to ${z2.home}/.. assuming modules will be next to the home or one level deeper |
568
569 4 Henning Blohm
See also [[Core Layout]]
570 1 Henning Blohm
571
}}
572 4 Henning Blohm
573 17 Henning Blohm
---
574 18 Henning Blohm
575 1 Henning Blohm
h2. Understanding Z2
576
577
Most of the concepts that make up z2 can be derived from the desire to efficiently develop standard Java Web Applications that are defined in a central system definition. Add to that the wish to avoid all that build complexity and the desire for a practically usable modularization approach.
578
579 4 Henning Blohm
{{collapse
580 1 Henning Blohm
Once you loose the ability to tweak some build script or configuration to describe how to package a Web app or some libraries, you need some structural hint and simple declarations providing sufficient information.
581
582
Secondy, assuming you want to apply changes at runtime, you need some way of determining what to unload at runtime, given some changed file. Again: Structural information needs to present that maps to runtime state. 
583
584
Finally, as we want some support for modular application development anyway, why not make modules our essential structure. As we have not only code but also Web Applications, Data Sources,  Background Jobs and much more to consider, we add components with type into the mix. Voila.
585
586
*Component Repositories* provides modules and components to z2. A component is prefixed by the module name:
587
588
<pre>
589
<global component name> = <module name>/<local component name>
590
</pre>
591
592
In fact, the typical component repository has a file system style structure that is made up exactly like that. 
593
594
Structure from repo root:
595
596
| /<module>/<cmp>.properties | A component <cmp> in module <module> that has no resources on its own.|
597
| /<module>/<cmp>/z.properties | A component <cmp> in module <module> that may have additional resources on its own.|
598
599
Note that some components, like Web applications and typically Java components have file resources, such as HTML files or Java source code files, while other components, such as main program declarations or data source declarations, so not.
600
601
There are some conventions around this naming scheme. In particular, by convention, whenever a component requires Java implementation, z2 will first look for a component named *java* of the same module. As for example in the Hello World example.
602
603
To give you an idea what this model translates to at runtime consider this: At runtime, the static component is turned into a Resource instance by a component type implementation (that, in fact, is provided by another, built-in component type). 
604
605
!uml1.png!
606
607
Dependencies, for example those between Java components, translate into dependencies between resources that are observed during invalidation of resources. This introduces invalidation and synchronization.
608
609
h3. A crucial concept of z2 is that of a synchronization. 
610
611
For fast development roundtrips and in some cases for general configuration updates, it is desirable to not require a complete restart of a Java Virtual Machine process but rather just to change runtime state accordingly. 
612
613
In z2 a synchronization describes the following process:
614
615
# Check for changes in component repositories
616
# Based on changes found, identify components affected and invalidate associated runtime resources incl. dependent resources.
617
# Try to attain target states
618
619
That is, whenever you do a change and trigger a synchronization from your IDE, this is exactly what happens: Identify what needs to be thrown away, make sure to remove dependent stuff as well,  bring up what needs to be running.
620
621
h3. A second crucial concept of z2 is that of *System Centric Development*
622
623
When working on a software system with many access points and high re-use on a service level, as is typical for business systems, staying quick integration with a team's changes is key. Component repositories can be fed from remotely accessible version control systems such as Subversion and Git. When connecting to a central, team-shared repository, every synchronization will make sure that you are up-to-date with the real source of truth. 
624
625
Using the dev repo, you can still isolate yourself from changes on part of the system that you are actively working on. After your modifications are completed, rebased, and locally tested, getting a clean and consistent state is just one synchronization away.
626
627
h3. The third and final concept is that of a compile-free environment
628
629
It is within the nature of the synchronization concept, that anything required to happen to have your software available for execution must have happened after synchronization completed. Most preparation steps are executed at first use. This includes the compilation of Java code. Z2 uses the Eclipse Java Compiler for that purpose.
630
631
h2. The Component Model
632
633
See [[z2-environment:Z2_Modules_intro]]
634
635
h2. Java Components
636
637
See [[z2-environment:Z2_Java_components_intro]]
638 4 Henning Blohm
639
}}