Search code examples
javajpastaticentityeclipselink

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


I am using Netbeans 7.1.1 and a Glassfish 3.1.2 server. As JPA provider I decided to use eclipse-link 2.3.0 which is shipped with Netbeans. Since I want to use lazy fetching and my project consists of roughly 45 JPA Entity classes which do have lots of relations among them, I decided to use static weaving. Moreover, the @Entity classes are in a separate Class Lib Project, whereas the persistence.xml resides in the EJB project.

I already followed the instructions here: http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving

I put the ant-task into the build-impl.xml file (below ). Is that correct when using Netbeans ? Here's the snippet from build-impl.xml:

<target name="-post-jar" description="New task definition for EclipseLink static weaving">
    <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/>
</target>
<target name="weaving" description="perform weaving" depends="-post-jar">
    <weave  source="${dist.jar}\MyProject.jar"
            target="${dist.jar}\MyProject_Weaved.jar"
            persistenceinfo="${dist.jar}..\..\MyProjectEE\MyProject-ejb\build\classes\META-INF\persistence.xml"
            loglevel="FINER">
        <classpath>
            <pathelement path="${dist.jar}\lib\eclipselink-2.3.0.jar"/>
            <pathelement path="${dist.jar}\lib\javaee-api-6.0.jar"/>
            <pathelement path="${dist.jar}\lib\jasypt-1.9.0.jar"/>
            <pathelement path="${dist.jar}\lib\javax.persistence-2.0.jar"/>
            <pathelement path="${dist.jar}\lib\org.eclipse.persistence.jpa.jpql_1.0.0.jar"/>
            <pathelement path="${dist.jar}\lib\joda-time-2.1.jar"/>
            <pathelement path="${dist.jar}\lib\jms.jar"/>
        </classpath>
    </weave>
</target>

All jar-files in the pathelement paths are also included as libraries in the Netbeans IDE. When hitting "Clean & Build", I now get the following error:

D:\workspace\MyProject\nbproject\build-impl.xml:703: taskdef class org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask cannot be found
using the classloader AntClassLoader[]

What do I make wrong here ?


Solution

  • 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.