openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] OpenJPA > Enhancement with Maven
Date Tue, 12 Apr 2011 04:13:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/5/_/styles/combined.css?spaceKey=openjpa&amp;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 &lt;build&gt; 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>        &lt;plugin&gt;
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;groupId&gt;org.apache.openjpa&lt;/groupId&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >            &lt;artifactId&gt;openjpa-maven-plugin&lt;/artifactId&gt;
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;version&gt;1.0&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;2.2.0-SNAPSHOT&lt;/version&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >            &lt;configuration&gt;
<br>                &lt;includes&gt;**/entities/*.class&lt;/includes&gt;
<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 &lt;build&gt; section of your pom.xml, like -</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    &lt;build&gt;
        ...
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.openjpa&lt;/groupId&gt;
            &lt;artifactId&gt;openjpa-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;2.2.0-SNAPSHOT&lt;/version&gt;
            &lt;configuration&gt;
                &lt;includes&gt;**/entities/*.class&lt;/includes&gt;
                &lt;excludes&gt;**/entities/XML*.class&lt;/excludes&gt;
                &lt;addDefaultConstructor&gt;<span class="code-keyword">true</span>&lt;/addDefaultConstructor&gt;
                &lt;enforcePropertyRestrictions&gt;<span class="code-keyword">true</span>&lt;/enforcePropertyRestrictions&gt;
            &lt;/configuration&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;id&gt;enhancer&lt;/id&gt;
                    &lt;phase&gt;process-classes&lt;/phase&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;enhance&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
            &lt;dependencies&gt;
                &lt;dependency&gt;
                    &lt;groupId&gt;org.apache.openjpa&lt;/groupId&gt;
                    &lt;artifactId&gt;openjpa&lt;/artifactId&gt;
                    &lt;!-- set the version to be the same as the level in your runtime
--&gt;
                    &lt;version&gt;1.2.2&lt;/version&gt;
                &lt;/dependency&gt;
            &lt;/dependencies&gt;
        &lt;/plugin&gt;
        ...
    &lt;/build&gt;
</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&amp;title=Enhancing+with+ANT&amp;linkCreation=true&amp;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">
      &lt;build&gt;
      &lt;!-- Copy the persistence.xml file to the build dir --&gt;
      &lt;!-- 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 --&gt;
      &lt;resources&gt;
          &lt;resource&gt;
            &lt;directory&gt; src/main/java &lt;/directory&gt;
            &lt;includes&gt;
              &lt;include&gt; **/*.xml &lt;/include&gt;
              &lt;/includes&gt;
          &lt;/resource&gt;
        &lt;/resources&gt;
        &lt;plugins&gt;
    .....           
          &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
            &lt;version&gt;1.2&lt;/version&gt;
            &lt;executions&gt;
              &lt;execution&gt;
                  &lt;phase&gt;process-classes&lt;/phase&gt;
                &lt;configuration&gt;
                  &lt;tasks&gt;
                      &lt;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>/&gt;
                      &lt;openjpac&gt;
                          &lt;classpath refid=<span class="code-quote">"maven.compile.classpath"</span>/&gt;
                      &lt;/openjpac&gt;
                  &lt;/tasks&gt;
                &lt;/configuration&gt;
                &lt;goals&gt;
                  &lt;goal&gt;run&lt;/goal&gt;
                &lt;/goals&gt;
              &lt;/execution&gt;
            &lt;/executions&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
    ....
      &lt;/build&gt;
</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&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message