Project

General

Profile

How to run a sample » History » Version 39

Henning Blohm, 16.09.2018 21:42

1 19 Henning Blohm
h1. How to run a sample
2 1 Henning Blohm
3 39 Henning Blohm
-- OUTDATED ---
4
5 1 Henning Blohm
Various z2-based sample system configurations have been prepared as Git repositories. 
6
7 23 Henning Blohm
Assuming you know the repository URL these three steps (with or without Eclipse) are all there is to do.
8 14 Henning Blohm
9 25 Henning Blohm
While these instructions are for Git users, they can be applied to the Subversion case quite similarly as described below.
10
11 27 Henning Blohm
*Note:* If you experience problems reaching out to the internet, you may need to configure some proxy settings. Please see [[How_to_proxy_settings]] for how that is done.
12
13 31 Udo Offermann
h1. Eclipse users
14 14 Henning Blohm
15 20 Henning Blohm
Most likely you will want to look at code or configuration files of a sample. That is why we recommend to start from within the Eclipse IDE. If you prefer the command line or another IDE, please proceed to [[How to Run a Sample#From the command line|From the command line]].
16 14 Henning Blohm
17 17 Henning Blohm
Open Eclipse with a new workspace in a new folder, say *sample*. Note: We will clone repositories as siblings to your workspace. So let's assume your workspace is *sample/workspace*.
18 1 Henning Blohm
19 19 Henning Blohm
h2. 1. Prepare a z2-base installation
20 1 Henning Blohm
21 17 Henning Blohm
As the location where repositories are cloned to matters, it is simplest you open the Git tab in the Eclipse preferences and enter "${workspace_loc}/.." as default repository location.
22 1 Henning Blohm
23 18 Henning Blohm
Open the Git Perspective and clone the "z2-base.core":http://redmine.z2-environment.net/projects/z2-base/repository/core repository from this URL *http://git.z2-environment.net/z2-base.core*. For convenience choose to import all projects into the workspace or do so after cloning has completed. You should end up having a project *core* in your workspace. That project is the z2 core that will fetch dependency resources as needed later on.
24 1 Henning Blohm
25 19 Henning Blohm
h2. 2. Clone the sample repository
26 17 Henning Blohm
27
Now repeat the same with the repository for the specific sample. It is important that the repository is cloned as a sibling to the core, So that the core can pick up modules defined in the sample.
28
29 22 Henning Blohm
h2. 3. Start and introspect
30 1 Henning Blohm
31
You can launch Z2 from Eclipse by the _launcher_ file in the root of the *core* project (or by navigating to *Run* / *External Tools* / *External Tools Configurations...* and pick the launcher). A GUI wrapping the console should open up and you are ready to go.
32 21 Henning Blohm
33 1 Henning Blohm
Once it is running, import the projects from the sample repository into your workspace, so that you can have a look at them. If you have previously installed the Eclipsoid plugin (see [[Step_3_-_First_steps_with_Z2_on_Git#Installation-of-the-Eclipsoid-plug-in]]) you can conveniently resolve all compilation dependencies with one click from within Eclipse.
34 31 Udo Offermann
35
h1. Using IntelliJ
36
37
[[IntelliJ z2 plugin]] shows how to install the z2 plugin and its basic features.
38 32 Udo Offermann
You can checkout the z2 repositories using VCS -> Checkout from Version Control... but make sure that you don't create a new project when IntelliJ asks you if "would you like to create a new IDEA project for ..."!
39
40
Furthermore make sure that the repository folders are located directly beneath the project folder:
41
<pre>
42
.../my-project
43 34 Udo Offermann
     /.idea
44 32 Udo Offermann
     /z2-base-core
45
     /z2-samples.xyz
46
</pre>
47
48 36 Udo Offermann
Once z2-base.core is checked out navigate to Preferences -> Project Settings -> z2-Environment and click "Search z2-Home" which should find the z2-base-core folder inside your project; press ok.
49
Still in the preference pane select Project Settings -> File Colors and add a new label to the local colors. As scope select "Armed z2-Modules" and choose a color you like and press ok and close the
50
Settings pane with ok. Now armed z2-modules will be displayed with the selected color.
51 1 Henning Blohm
52
Now launch the z2-environment from Tools -> Launch z2-environment...
53
54 36 Udo Offermann
Once it is running, import the projects from the sample repository into your workspace, by selecting the menu "Manage z2-modules" !z2_module.png! inside the toolbar. This opens a popup window showing 
55
the checked out repositories as root folders and their modules as children. Choose the modules belonging to the samples repository or simply select the sample repository node and press ok. 
56
This will create modules for each selected z2-modules inside your project. Since z2-modules in the samples repository are armed by default the modules should be displayed with the color selected above.
57
58 37 Udo Offermann
Of course the java classes will contain a lot of errors coming from unresolved dependencies. Choose "Resolve z2-classpath" !z_refresh.png! in the toolbar which will download all missing jars and add them
59
to the modules.
60 35 Udo Offermann
61 19 Henning Blohm
h1. From the command line
62 17 Henning Blohm
63
All you need is Java Runtime Environment (JRE) of at least version 6. Other pre-requisites, for example some database setup may be required based on the specific example, i.e. stuff that cannot be covered here.
64 1 Henning Blohm
65 19 Henning Blohm
h2. 1. Prepare a z2-base installation
66 2 Henning Blohm
67
Create a folder to hold the installation. We will assume that folder is called *sample*
68
69
In *sample* execute
70 11 Henning Blohm
71 5 Henning Blohm
<pre>
72 11 Henning Blohm
git clone -b master http://git.z2-environment.net/z2-base.core
73 2 Henning Blohm
</pre>
74
75
Go into *sample/z2-base.core/run/bin* and run 
76
77
<pre>
78
./gui.sh
79
</pre>
80
81
or 
82
83
<pre>
84
gui.bat
85 1 Henning Blohm
</pre>
86 3 Henning Blohm
87 2 Henning Blohm
depending on your operating system. A simple graphical console should open up that displays the console log output of the z2 &lt;home&gt; and worker processes - as explained in http://www.z2-environment.eu/check_it_out.
88
89 18 Henning Blohm
At the first start, the environment will download required resources, which may take a few minutes - depending on your network bandwidth. Subsequent starts will be much quicker. Eventually the server should be up and you can go to the basic admin view at http://localhost:8080/adm (use z* with password z) to verify everything is cool. You do actually not need to start before completing step 3. But checking things are working doesn't hurt either.
90 6 Henning Blohm
91 1 Henning Blohm
Stop the environment again by either pressing Ctrl+C on the console where you started the GUI or by clicking the Exit button on the GUI.
92 3 Henning Blohm
93 1 Henning Blohm
h2. 2. Clone the specific sample repository
94 3 Henning Blohm
95 1 Henning Blohm
Given the sample repository is called *z2-samples.sampleX*, go into *sample* once more and run 
96 3 Henning Blohm
97 1 Henning Blohm
<pre>
98
git clone -b master http://git.z2-environment.net/z2-samples.sampleX
99 5 Henning Blohm
</pre>
100 3 Henning Blohm
101 18 Henning Blohm
h2. 3. Start 
102
103
Now start the environment again as described above. The environment will now run with the sample configuration and all required dependencies.
104 4 Henning Blohm
105
In other words: That's it.
106 3 Henning Blohm
107 19 Henning Blohm
h2. Why does that actually work?
108 3 Henning Blohm
109
If you care, here is how everything falls into place:
110 13 Henning Blohm
111 3 Henning Blohm
The z2-base.core repository contains a z2 core installation that is bound to a remote "system repository" at "http://git.z2-environment.net/z2-base.base":http://redmine.z2-environment.net/projects/z2-base/repository/base?rev=master. As it is by now best practice with z2, that repository contains an *environment* module that describes system specific settings such as other repositories.
112
113
By cloning the sample repository you put an override of *environment* module into view of the _dev repository_. That is, the local server will take your local definitions with preference over the remote definitions. These may include other remote component repositories such as *z2-addons.spring*.
114
115
In addition the sample repository contains all the modules holding code and other resources that implement the actual sample.
116
117
If you already understand how the _dev repository_ works, you will not be surprised to find files called LOCAL in the module folders of cloned repository's workspace.
118
119 24 Henning Blohm
120
h2. References
121 3 Henning Blohm
122 38 Henning Blohm
* Dev Repository: http://www.z2-environment.eu/v26doc#Workspace%20Development%20Using%20the%20Dev%20Repository