开发者

Static Weaving for EclipseLink with Eclipse WTP

I've got a project running on Tomcat within Eclipse WTP that deploys with some JPA entities. I would like to enable ChangeTracking on these entities, but this requires enabling weaving. S开发者_JAVA技巧ince Tomcat doesn't allow for dynamic weaving, I need to do this with static weaving.

Is this possible? Eclipse's Dali plugin doesn't seem to have any facility for static weaving.


Yes, very possible I do this all the time. Also I use Jetty (J2EE Preview) in Eclipse WTP it's very fast and works well, on to the weaving though. Make a weave.xml file that ant can handle like this:

<?xml version="1.0"?>
<project name="MyProject" default="weaving" basedir=".">
  <property environment="env"/> 

    <path id="weavingclasspath"> 
      <fileset dir="${basedir}\\web\\WEB-INF\\lib">
        <include name="**/*.jar"/>
      </fileset>
        <fileset dir="${basedir}\\antlib">
        <include name="**/*.jar"/>
      </fileset>
      <pathelement location="classes"/>
      <dirset dir="${basedir}\\build">
        <include name="**/classes"/>
      </dirset>
    </path>


    <target name="define.task" description="New task definition for EclipseLink static weaving" > 
      <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask">
        <classpath refid="weavingclasspath"/> 
        </taskdef>
    </target> 

    <target name="weaving" description="perform weaving" depends="define.task"> 
        <weave loglevel="WARNING" source="${basedir}\\build\\classes\\"  target="${basedir}\\build\\classes\\">
     <classpath refid="weavingclasspath"/> 
     </weave>
    </target> 

</project> 

Put this in your project root and execute it as an Ant Task. Make sure you refresh your project when done since all the .class files for your entities will be weaved. I actually link this task to the eclipse build process so it's automatic. You might need to modify some of the file paths in the ant script for your project to get it to work, but you should get the idea. My antlib has servlet.jar in it (I don't remember why) and my WEB-INF/lib has all my web project jars as well as eclipselink.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜