How to apply Static Weaving Ant Task with Eclipse-Link JPA in Netbeans?

随声附和 提交于 2019-12-05 01:21:00

You need to add the eclipselink.jar and javax.persistence.jar to the Ant classpath.

In Netbeans go to Tools / Options / Miscellaneous / Ant, and edit the classpath there.

I am also using Netbeans 8.0.1 for developing java ee projects with Eclipselink 2.4.2 in TomEE 1.7.0 and I just put the following into my build.xml (I never modify build-impl.xml because Netbeans can overwrite it when something is modified in the configuration, building):

<target name="--weaving-def" description="New task definition for EclipseLink static weaving" depends="dist">
    <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"
             classpath="${j2ee.platform.classpath}">
    </taskdef>
</target>
<target name="weaving" description="perform weaving" depends="--weaving-def">
    <weave source="${build.classes.dir}"
           target="${build.classes.dir}"
           loglevel="INFO">
        <classpath path="${j2ee.platform.classpath}:${javac.classpath}"/>  
    </weave>
</target>

You can see that I have used only the commonly used variables in all Netbeans Java EE Ant projects. I have not defined any jar directly just the variables which defined in the project already.

In my implementation I am using exploded directory structure and my persistence.xml is under the

${build.classes.dir}/META-INF/persistence.xml

The most important thing was to define the classpath correctly.

Now if I run

ant weaving 

the static weaving will be done. It takes approx 15 seconds more to build so I am building this way only on the testing server and the production server and not in my development environment.

If I just simple run (or use the Netbeans build menu)

ant dist

the building will be resulted normal without weaving.

Of course I have a weaving definition in my persistence.xml like this:

<persistence-unit name="MY-PU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>mydata</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
        <property name="eclipselink.logging.level" value="INFO"/>
        <property name="eclipselink.weaving" value="static"/>
    </properties>
</persistence-unit>

I also had to include org.eclipse.persistence.jpa.jpql_1.0.1.jar and org.eclipse.persistence.jpa.modelgen.processor-2.3.2.jar in order to bring weaving to live. Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!