| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title xmlns:d="http://docbook.org/ns/docbook">Chapter 2. Starting Client Project</title><link rel="stylesheet" type="text/css" href="css/cayenne-doc.css"><meta xmlns:d="http://docbook.org/ns/docbook" name="keywords" content="Cayenne 4.0 documentation"><meta xmlns:d="http://docbook.org/ns/docbook" name="description" content="User documentation for Apache Cayenne version 4.0"><link rel="home" href="index.html" title="Getting Started with Cayenne ROP (Remote Object Persistence)"><link rel="up" href="getting-started-rop-part2.html" title="Part II. Remote Object Persistence Quick Start"><link rel="prev" href="getting-started-rop-part2.html" title="Part II. Remote Object Persistence Quick Start"><link rel="next" href="ch03.html" title="Chapter 3. Setting up Hessian Web Service"><script xmlns:d="http://docbook.org/ns/docbook" type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-7036673-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></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div xmlns:d="http://docbook.org/ns/docbook" class="navheader"><table width="100%" summary="Navigation header"><tr><th class="versioninfo">v.4.0 (4.0.M5)</th><th align="center">Chapter 2. Starting Client Project</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="getting-started-rop-part2.html">Prev</a> </td><th width="60%" align="center"><a accesskey="u" href="getting-started-rop-part2.html">Part II. Remote Object Persistence Quick Start</a></th><td width="20%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="d0e52"></a>Chapter 2. Starting Client Project</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="ch02.html#create-rop-client-project">Create an ROP Client Project in Eclipse</a></span></dt><dt><span class="section"><a href="ch02.html#create-client-java-classes">Create Client Java Classes</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="create-rop-client-project"></a>Create an ROP Client Project in Eclipse</h2></div></div></div><p>Creation of a new Eclipse project has been discussed in some details in "Getting |
| Started with Cayenne" guide, so we will omit the screenshots for the common |
| parts.</p><p>In Eclipse select "File > New > Other..." and then "Maven > Maven Project". |
| Click "Next". On the following screen check "Create a simple project" checkbox and click |
| "Next" again. In the dialog shown on the screenshot below, enter "org.example.cayenne" |
| for the "Group Id" and "tutorial-rop-client" for the "Artifact Id" (both without the |
| quotes) and click "Finish". </p><p>Now you should have a new empty project in the Eclipse workspace. Check that the |
| project Java compiler settings are correct. Rightclick on the "tutorial-rop-client" |
| project, select "Properties > Java Compiler" and ensure that "Compiler compliance |
| level" is at least 1.5 (some versions of Maven plugin seem to be setting it to 1.4 by |
| default).</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title"><a name="create-client-java-classes"></a>Create Client Java Classes</h2></div></div></div><p>The client doesn't need the XML ORM mapping, as it is loaded from the server. However |
| it needs the client-side Java classes. Let's generate them from the existing |
| mapping:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Start CayenneModeler and open cayenne.xml from the "tutorial" project (located |
| under "tutorial/src/main/resources", unless it is already open.</p></li><li class="listitem"><p>Select the "datamap" DataMap and check "Allow Client Entities" |
| checkbox.</p></li><li class="listitem"><p>Enter "org.example.cayenne.persistent.client" for the "Client Java Package" |
| and click "Update.." button next to the field to refresh the client package of |
| all entities.</p><p><span class="inlinemediaobject"><img src="images/datamap-enableclient.png"></span></p></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>Select "Tools > Generate Classes" menu.</p></li><li class="listitem"><p>For "Type" select "Client Persistent Objects".</p></li><li class="listitem"><p>For the "Output Directory" select "tutorial-rop-client/src/main/java" folder |
| (as client classes should go in the <span class="italic">client</span> |
| project).</p></li><li class="listitem"><p>Click on "Classes" tab and check the "Check All Classes" checkbox (unless it |
| is already checked and reads "Uncheck all Classes").</p></li><li class="listitem"><p>Click "Generate".</p></li></ul></div><p>Now go back to Eclipse, right click on "tutorial-rop-client" project and select |
| "Refresh" - you should see pairs of classes generated for each mapped entity, same as on |
| the server. And again, we see a bunch of errors in those classes. Let's fix it now by |
| adding two dependencies, "cayenne-client" and "resin-hessian", in the bottom of the |
| pom.xml file. We also need to add Caucho M2 repository to pull Hessian jar files. The |
| resulting POM should look like this:</p><pre class="programlisting"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| <modelVersion>4.0.0</modelVersion> |
| <groupId>org.example.cayenne</groupId> |
| <artifactId>tutorial-rop-client</artifactId> |
| <version>0.0.1-SNAPSHOT</version> |
| |
| <dependencies> |
| <dependency> |
| <groupId>org.apache.cayenne</groupId> |
| <artifactId>cayenne-client</artifactId> |
| <!-- Here specify the version of Cayenne you are actually using --> |
| <version>4.0.M3</version> |
| </dependency> |
| <dependency> |
| <groupId>com.caucho</groupId> |
| <artifactId>hessian</artifactId> |
| <version>4.0.38</version> |
| </dependency> |
| </dependencies> |
| |
| <repositories> |
| <repository> |
| <id>caucho</id> |
| <name>Caucho Repository</name> |
| <url>http://caucho.com/m2</url> |
| <layout>default</layout> |
| <snapshots> |
| <enabled>false</enabled> |
| </snapshots> |
| <releases> |
| <enabled>true</enabled> |
| </releases> |
| </repository> |
| </repositories> |
| </project></pre><p>Your computer must be connected to the internet. Once you save the pom.xml, Eclipse |
| will download the needed jar files and add them to the project build path. After that |
| all the errors should disappear.</p><p>Now let's check the entity class pairs. They look almost identical to their server |
| counterparts, although the superclass and the property access code are different. At |
| this point these differences are somewhat academic, so let's go on with the |
| tutorial.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="getting-started-rop-part2.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="getting-started-rop-part2.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part II. Remote Object Persistence Quick Start </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 3. Setting up Hessian Web Service</td></tr></table></div></body></html> |