blob: c7a89b55816253430b1fcf84d85aa0107e4a009f [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title xmlns:d="http://docbook.org/ns/docbook">Chapter&nbsp;2.&nbsp;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 3.1 documentation"><meta xmlns:d="http://docbook.org/ns/docbook" name="description" content="User documentation for Apache Cayenne version 3.1"><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&nbsp;II.&nbsp;Remote Object Persistence Quick Start"><link rel="prev" href="getting-started-rop-part2.html" title="Part&nbsp;II.&nbsp;Remote Object Persistence Quick Start"><link rel="next" href="ch03.html" title="Chapter&nbsp;3.&nbsp;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.3.1 (3.1)</th><th align="center">Chapter&nbsp;2.&nbsp;Starting Client Project</th><th></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="getting-started-rop-part2.html">Prev</a>&nbsp;</td><th width="60%" align="center"><a accesskey="u" href="getting-started-rop-part2.html">Part&nbsp;II.&nbsp;Remote Object Persistence Quick Start</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch03.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter&nbsp;2.&nbsp;Starting Client Project"><div class="titlepage"><div><div><h2 class="title"><a name="d0e51"></a>Chapter&nbsp;2.&nbsp;Starting Client Project</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><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" title="Create an ROP Client Project in Eclipse"><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 &gt; New &gt; Other..." and then "Maven &gt; 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 &gt; 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" title="Create Client Java Classes"><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"><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"><li class="listitem"><p>Select "Tools &gt; 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 "Entities" 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">&lt;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"&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;org.example.cayenne&lt;/groupId&gt;
&lt;artifactId&gt;tutorial-rop-client&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.cayenne&lt;/groupId&gt;
&lt;artifactId&gt;cayenne-client&lt;/artifactId&gt;
&lt;!-- Here specify the version of Cayenne you are actually using --&gt;
&lt;version&gt;3.1M3&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.caucho&lt;/groupId&gt;
&lt;artifactId&gt;resin-hessian&lt;/artifactId&gt;
&lt;version&gt;3.1.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;caucho&lt;/id&gt;
&lt;name&gt;Caucho Repository&lt;/name&gt;
&lt;url&gt;http://caucho.com/m2&lt;/url&gt;
&lt;layout&gt;default&lt;/layout&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;releases&gt;
&lt;enabled&gt;true&lt;/enabled&gt;
&lt;/releases&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;/project&gt;</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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="getting-started-rop-part2.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part&nbsp;II.&nbsp;Remote Object Persistence Quick Start&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;3.&nbsp;Setting up Hessian Web Service</td></tr></table></div></body></html>