<html>
<head>
<base href="https://cwiki.apache.org/confluence">
<link rel="stylesheet" href="/confluence/s/2042/9/5/_/styles/combined.css?spaceKey=openjpa&forWysiwyg=true"
type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://cwiki.apache.org/confluence/display/openjpa/Enhancement+with+Maven">Enhancement
with Maven</a></h2>
<h4>Page <b>edited</b> by <a href="https://cwiki.apache.org/confluence/display/~michael.d.dick@gmail.com">Michael
Dick</a>
</h4>
<div id="versionComment">
<b>Comment:</b>
Update groupId, version, and plugin information<br />
</div>
<br/>
<h4>Changes (5)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-unchanged" >h2. Using the openjpa-maven-plugin
<br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">There
is a [Maven plugin provided by the Codehaus project|http://mojo.codehaus.org/openjpa-maven-plugin/index.html],
which uses OpenJPA to enhance entities during a Maven build. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">The
Maven plugin, formerly provided by the Codehaus project is now part of OpenJPA 2.2.0. The
plugins documentation can be found [here|http://people.apache.org/~mikedd/openjpa/openjpa-maven-plugin/]
until it finds a permanent home one the openjpa site. <br></td></tr>
<tr><td class="diff-unchanged" > <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">The
previous versions of the plugin can be found at the [Codehaus project|http://mojo.codehaus.org/openjpa-maven-plugin/index.html]
<br> <br></td></tr>
<tr><td class="diff-unchanged" >For example, to enhance you source
entity classes after they have been compiled (but exclude any POJO classes that rely upon
orm.xml maappings), add the openjpa-maven-plugin to the <build> section of your
pom.xml, like - <br>{code} <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" > ... <br> <plugin>
<br></td></tr>
<tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;"><groupId>org.codehaus.mojo</groupId></span>
<span class="diff-added-words"style="background-color: #dfd;"><groupId>org.apache.openjpa</groupId></span>
<br></td></tr>
<tr><td class="diff-unchanged" > <artifactId>openjpa-maven-plugin</artifactId>
<br></td></tr>
<tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;"><version>1.0</version></span>
<span class="diff-added-words"style="background-color: #dfd;"><version>2.2.0-SNAPSHOT</version></span>
<br></td></tr>
<tr><td class="diff-unchanged" > <configuration>
<br> <includes>**/entities/*.class</includes>
<br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h2><a name="EnhancementwithMaven-Usingtheopenjpamavenplugin"></a>Using
the openjpa-maven-plugin</h2>
<p>The Maven plugin, formerly provided by the Codehaus project is now part of OpenJPA
2.2.0. The plugins documentation can be found <a href="http://people.apache.org/~mikedd/openjpa/openjpa-maven-plugin/"
class="external-link" rel="nofollow">here</a> until it finds a permanent home one
the openjpa site. </p>
<p>The previous versions of the plugin can be found at the <a href="http://mojo.codehaus.org/openjpa-maven-plugin/index.html"
class="external-link" rel="nofollow">Codehaus project</a></p>
<p>For example, to enhance you source entity classes after they have been compiled (but
exclude any POJO classes that rely upon orm.xml maappings), add the openjpa-maven-plugin to
the <build> section of your pom.xml, like -</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<build>
...
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.2.0-SNAPSHOT</version>
<configuration>
<includes>**/entities/*.class</includes>
<excludes>**/entities/XML*.class</excludes>
<addDefaultConstructor><span class="code-keyword">true</span></addDefaultConstructor>
<enforcePropertyRestrictions><span class="code-keyword">true</span></enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<!-- set the version to be the same as the level in your runtime
-->
<version>1.2.2</version>
</dependency>
</dependencies>
</plugin>
...
</build>
</pre>
</div></div>
<p>There are other goals available to create the Entity to SQL mapping and Entity to
XML Schema mapping, which are documented under the <a href="http://mojo.codehaus.org/openjpa-maven-plugin/plugin-info.html"
class="external-link" rel="nofollow">Goals section</a> on the plugin website.</p>
<h2><a name="EnhancementwithMaven-Usingthemavenantrunplugin"></a>Using the
maven-antrun-plugin</h2>
<p>You can use the maven-antrun-plugin to launch the OpenJPA enhancer task using ANT.
The steps are nearly identical to the ones for <a href="/confluence/pages/createpage.action?spaceKey=openjpa&title=Enhancing+with+ANT&linkCreation=true&fromPageId=118022"
class="createlink">Enhancing with ANT</a> (again, you may not need to move the persistence.xml
file to the build directory, but I did for this write-up).</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<build>
<!-- Copy the persistence.xml file to the build dir -->
<!-- You can skip <span class="code-keyword">this</span> step <span
class="code-keyword">if</span> you put the persistence.xml in src/main/resources/META-INF
instead of src/main/java/META-INF -->
<resources>
<resource>
<directory> src/main/java </directory>
<includes>
<include> **/*.xml </include>
</includes>
</resource>
</resources>
<plugins>
.....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<taskdef name=<span class="code-quote">"openjpac"</span>
classname=<span class="code-quote">"org.apache.openjpa.ant.PCEnhancerTask"</span>
classpathref=<span class="code-quote">"maven.compile.classpath"</span>/>
<openjpac>
<classpath refid=<span class="code-quote">"maven.compile.classpath"</span>/>
</openjpac>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
....
</build>
</pre>
</div></div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;">
<a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
</div>
<a href="https://cwiki.apache.org/confluence/display/openjpa/Enhancement+with+Maven">View
Online</a>
|
<a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=118022&revisedVersion=3&originalVersion=2">View
Changes</a>
|
<a href="https://cwiki.apache.org/confluence/display/openjpa/Enhancement+with+Maven?showComments=true&showCommentArea=true#addcomment">Add
Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
|