Step 3 - First steps with Z2 on Git » History » Revision 26
Revision 25 (Udo Offermann, 11.09.2012 17:20) → Revision 26/69 (Henning Blohm, 11.09.2012 17:51)
h1. First steps [[How_to_install_z2_v21|prev]] :: [[Z2_v21|home]] h2. Prerequisites You need a cloned z2-base.core repository as described on the [[How_to_install_z2_v21|previous]] page. Furthermore you need the "Eclipse-IDE":http://www.eclipse.org (one of Galileo, Helios, Indigo or Juno is fine) and the "Egit plug-in:":http://www.eclipse.org/egit. h2. First steps with the z2-environment Next, we will look at the steps to development for Z2 using Eclipse. Please stop the server before you continue. In order to have modules from local repositories discovered by Z2, it is required for the repositories and workspace to be siblings to each other. Go back to the "z2-base" directory (@cd ../../..@, if you are still inside the "run/bin" directory) and create a folder called "workspace" - this will be used as the workspace root for Eclipse: <pre> :bin$ cd ../../.. :z2-base$ mkdir workspace :z2-base$ ls -l total 0 0 drwxr-xr-x 2 mr_x staff 68 7 Sep 16:34 workspace 0 drwxr-xr-x 12 mr_x staff 408 7 Sep 15:11 z2-base.core :z2-base$ </pre> Now start Eclipse and choose @z2-base/workspace@ as your workspace folder. We will add the core repository to the EGit repositories view. Detailed documentation on how to work with EGit can be found on the "EGit Wiki pages":http://wiki.eclipse.org/EGit/User_Guide. In the Git perspective choose "Add an existing local Git repository". In the "Directory" field type in the path to the ".../z2-base" directory. After hitting "search" the search results should list the *z2-base.core* repository, click "finish" and the repositories view should look like this: !EGit_repo_view_with_z2-core.png! (Note: Next time you may of course skip the command line approach and clone the *z2-base.core* repository from within Eclipse.) Now import the core project from the repository. Right-click the repository, choose "Import projects..." from the context menu and click "next" and then "finish". On the Java perspective the "core" project should be now available in the package explorer: !z2_core_project_in_package_explorer.png! The core project contains two launch entries, one for Linux/Mac OS and one for Windows. Right click the one that fits to your OS and choose "Run As >" and "z2_base". This starts the z2-environment again and opens the z2-gui inside a new window labeled "Z2 Home (z2-base v2.1)": !z2_gui.png! From now on you will find the z2-base launch entries in Eclipse "External Tools" (either inside "Run", "External Tools >" or click the "External Tools" button in the toolbar). The z2-Environment provides an Eclipse plug-in called "Eclipsoid" that has a lot of neat utilities and one really important feature: Dependency resolution from a running z2-Environment. Here's the catch: When developing with Eclipse, projects in your workspace may require Java types from other projects to compile. Eclipse will try to verify that, every time you save a source code modification. When working on a non-trivial system, you may have a lot of dependencies that you will typically not want to see clutter your workspace. That is where the plugin comes into the game. This way you can checkout and focus on a project subsets while the Eclipsoid plug-in provides the transitive closure of all required prjects and libraries. Other features provided by the Eclipsoid plug-in that are explained in more details on the [[Eclipsoid]] wiki pages. h2. Installation of the Eclipsoid plug-in The z2-environment that you just started contains the update site update-site for the Eclipsoid plug-in. Open the software update/installation wizard (in Indigo it's located at "Help/Install New Software...") and use the URL http://localhost:8080/eclipsoid/update as update-site URL (the field labled "Work with"): !Install_Eclipsoid.png! (Your actual Please note that the Eclipsoid version may differ will be different because the screenshots are made with an intermediate version of course.) the plug-in. Complete the installation wizard (you can speed up the installation procedure by deselecting "Contact all update sites during install...") and restart Eclipse. Now you should see a new menu entry labled "z2-Environment" and two new icons: !Eclipsoid_menu_entries_and_icons.png! h2. Changing source code and check the result To change source code, we need a an open project in Eclipse. Let's We're going to change the hello-world Web web application that is contained which remains in the samples repository. To do so, we need This requires to a) make the Git repository available in EGit, b) import the project into Eclipse and c) change the project and check the result. The Eclipsoid plug-in simplifies these steps. Since the z2-environment knows the repository landscape, we can ask it to share this knowledge with us. In the new "z2-environment" menu choose the entry labled "z2-Repositories view". This will open a view like this: !z2-Repositories-view.png! This view lists all repositories known by the running this system. The Eclipsoid plug-in connects by default to the Eclipsoid Web Eclpsoid web application on http://localhost:8080 that which provides a lot of online information about the running environment. Note that the server. The connection can be customized on the "z2-environment" preference page. There You can see that there are currently two repositories listed: One listed; one called *com.zfabrik.boot.config/systemRepository* _com.zfabrik.boot.config/systemRepository_ containing the Z2 z2 foundation services and one called *environment/samplesRepository* _environment/samplesRepository_ containing some sample applications including the hello hellow world Web application. web applciation. Now right-click on the samples repository and choose "Clone Git repository" from the context menu. This will create a clone from http://git.z2-environment.net/z2-base.samples next to the core repository inside your z2-base directory. You can check this out by double clicking on the samples repository (note - please note that the entry now looks like a hypelink with blue text color). color. Switch back to the Java java perspective and expand unfold the "environment/sampleRepository" node and further its "z2-projects" child node. You child. Now you will see all projects that which are stored inside this repository. Right-click the "com.zfabrik.samples.helloworld" project and choose "Import Project" from the context menu. This does the same as the import project action of the Git repositories perspective - without switching perspective, but you don't have to switch the perspectives. Once the project was is imported go to the Java Package Explorer view and drill down to +com.zfabrik.samples.helloworld / java/src.impl / com.zfabrik.samples.helloworld / HelloWorldServlet.java+, open the the class via double click. The result should look like this: !HelloWorldServlet_class.png! In You'll see the source code you will see and a lot of red x-markers indicating telling you that Eclipse is not able to cannot resolve certain identifiers. If you want you can check the classpath of the Hello World project and indeed there are only three entries: One one for the JRE, one for the sources, sources and one called "Eclipsoid: z2-Environment Build Container". This container will resolve the incomplete classpath when it is asked to do so. Either You can either select the entry "Resolve z2-Project classpaths", click the new icon !z2_resolve_icon.png!, !z2_resolve_icon.png! or simply hit <Alt+R> to trigger a refresh of that build container. <Alt+R>. Now all red x-markers should be gone. Next Now we want to change the code: You code; you can change whatever you like, e.g. replace "Hello World!" by "Hello Earth!" and save it. To make this change effective on the running environment, available, we have to tell the server two things: Firstly that 1. That it should check for changed source code sources and secondly 2. that it should - beside all connected conencted Git repositories - consider our local version as well. From the Z2 z2 point of view the Eclipse workspace worksapce is a repository as well. We call it well - it's called the _dev-repository_ because it contains the latest ongoing development. newest developed stuff. When we ask the Z2 z2 server to check for new changes (we say "to (that's called to _synchronize_ the server"), server), it will find two versions of the Hello World hello world project: one inside *environment/samplesRepository* _environment/samplesRepository_ and one inside the _dev-repository_ which is your Eclipse workspace. So which one should it take? To solve this "conflict" the _dev-repository_ has a switch for each project which can be "armed" and "disarmed". If it is it's "disarmed" - which is the default - the version in the Git repository will win. If it's "armed" our version in the workspace will win. So we need to "arm" the Hello World project: Right-click the project "com.zfabrik.samples.helloworld" in the Java Package Explorer and choose "Arm z2-Projects": !Howto_arm_z2-projects.png! You will notice that there is will be now a green "z" decoration at the upper left edge of the Java icon in the package explorer: !green_z_decoration.png!. After we specified that the workspace version of the Hello World project should win over the one in the Git repository we can trigger the z2 synchronization: syncronization: Choose "Sync with z2-environment" from the "z2-environment" menu, click the new z-icon !z2_sync.png!, !z2_sync.png! or simply hit <Alt+Y>. You can also switch to the z2-gui and click the "Sync" button. As described before, before the Eclipsoid plug-in talks to the z2 server via http. In situations where the web server cannot be started, the Eclipsoid web applicaton will not be available. In this case the z2-gui is the only way to trigger a synchronization (except of a shutdown and restart). shutdown/restart). You will also see that the log-messages in the z2-gui log pane has changed and that the server has invalidated and restarted one resource: <pre> 09/11 15:34:54 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR environment/samplesRepository (origin=http://git.z2-environment.net/z2-base.samples, branch=v2.1, OPTIONAL) within 56msec 09/11 15:34:54 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR com.zfabrik.boot.config/systemRepository (origin=http://git.z2-environment.net/z2-base.base, branch=v2.1) within 29msec 09/11 15:34:54 [34]...hronizationRunner[800]: Found 1 invalidation candidate resources 09/11 15:34:54 [34]...hronizationRunner[800]: Invalidated 0 resources 09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...stemStateResource[800]: Left system state: environment/webWorkerUp 09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...pp.WebAppResource[800]: Stopping Web App (/helloworld): com.zfabrik.samples.helloworld/web 09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...worker.WorkerSoul[800]: Invalidated 1 resources 09/11 15:34:54 [31]...ent/webWorker@0.2[800]: 09/11 15:34:54 [19]...pp.WebAppResource[800]: Starting WebApp: com.zfabrik.samples.helloworld/web 09/11 15:34:55 [31]...ent/webWorker@0.2[800]: 09/11 15:34:55 [19]...pp.WebAppResource[800]: Done starting Web App (/helloworld): com.zfabrik.samples.helloworld/web 09/11 15:34:55 [31]...ent/webWorker@0.2[800]: 09/11 15:34:55 [19]...stemStateResource[800]: System state attained: environment/webWorkerUp 09/11 15:34:55 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR com.zfabrik.boot.config/systemRepository (origin=http://git.z2-environment.net/z2-base.base, branch=v2.1) within 29msec 09/11 15:34:55 [34]...entRepositoryImpl[800]: Pulled deltas from GitCR environment/samplesRepository (origin=http://git.z2-environment.net/z2-base.samples, branch=v2.1, OPTIONAL) within 30msec </pre> Now it's time to check the result: http://localhost:8080/helloworld - voilà! Please You can now repeat these steps a few times: Change change the source code, hit <Alt+Y> and check the result, so you will get a feeling of how fast developement roundtrips can be!