Allowing static weaving JPA (eclipselink)

I am new to Eclipselink. I wrote a couple of web services (deployed to Tomcat) using Eclipselink / Java. These web services use several entity classes. To improve the performance of web services, I try to use static weaving. I found out that I can enable this either from the command line or using the Eclipselink weave ant script. Since I use eclipse and build my WAR from eclipse, I'm not sure where to use the "weave" ant task in the Eclipse IDE. So, I tried the command line option as follows:

java org.eclipse.persistence.tools.weaving.jpa.StaticWeave -persistenceinfo c:\eclipse \workspace\employeeModel\src -classpath c:\eclipse\workspace\employeeModel\src -log c:\log\weave.log -loglevel FINEST c:\eclipse\workspace\employeeModel\src c:\eclipse \workspace\employeeModel\src 

[The last two paths in the command: c: \ eclipse \ workspace \ employeeModel \ src c: \ eclipse \ workspace \ employeeModel \ src refer to the source and target, respectively]

When I ran this, he logged the following in the log file: [EL Finest]: 2012-03-05 17: 22: 49.806 - ServerSession (8880493) - Thread (Thread [main, 5, main]) - property = eclipselink.jpa .uppercase-column-names; default value = false [EL Finer]: 2012-03-05 17: 22: 49.837 - ServerSession (8880493) - Thread (Thread [main, 5, main]) - Search for the default mapping file in the file: / c: / eclipse / Workspace / employeeModel / SRC / [EL Finer]: 2012-03-05 17: 22: 49.852 - ServerSession (8880493) - Subject (Subject [main, 5, main]) - Search for the default mapping file in the file: / c: / eclipse / Workspace / employeeModel / SRC /

From the log, it looks like staticWeave did not complete successfully. But it also did not cause errors on the command line.

Since I used the same path for both the source (.java) and target, staticWeave overwrite my source files (.java files). I'm not sure if staticWeave (the command I worked on above) will create class files (.class) or overwrite the source code (.java).

I am also not sure if I did the right thing. How can I check if static weaving is really turned on? If what I did is wrong, can someone help me understand how to use the Eclipselink weave ant task in the Eclipse IDE? or the error I make in the command line option. Also, I would like to know if staticWeave will actually overwrite the source files or create byte codes (.class files).

I spent several hours to do this work, but to no avail. Can someone shed some light on this?

Appreciate your help.

+4
source share
4 answers

Static weaving interlaces .class files and outputs .class files. It does not work with .java files. Usually you give it a jar file and it outputs a new jar file.

See, http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving

+3
source

Add this code to your build.xml file:

 <target name="-post-jar"> <antcall target="weaving"/> </target> <target name="define.task" 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="define.task"> <weave source="C:\<projectpath>\dist\${ant.project.name}.jar" target="C:\<projectpath>\dist\woven-${ant.project.name}.jar" persistenceinfo="D:\<projectpath>\lib\persistence.jar" loglevel="FINE" log="C:\<projectpath>\weaver.log"> <classpath> </classpath> </weave> </target> 

In the code, change the <projectpath> to the path where your source code is located. And persistenceinfo points to another jar (persistence.jar) that only contains persistence.xml , since I use the same persistence.xml file among several projects. If you are not using a separate jar for the persistence.xml file, delete this property and use persistencexml=<path-to-persistence.xml-file>\META-INF\persistence.xml .

In addition, you need to add the eclipselink.jar and javax.persistence...jar files to the Ant class path. If you are using Netbeans, go to Tools | Options | Java | Ant Tools | Options | Java | Ant Tools | Options | Java | Ant , there you can add these files to the classpath.

Using the previous code, every time you compile it, you will create a new file with the woven- prefix, which is your new javar file.

+3
source

You can use the exploded directory structure instead of jar so that your class files are intertwined if you want.

0
source

If the project is maven, you can use this maven plugin to weave a jar

  <plugins> ... <plugin> <groupId>de.empulse.eclipselink</groupId> <artifactId>staticweave-maven-plugin</artifactId> <version>1.0.0</version> <executions> <execution> <phase>process-classes</phase> <goals> <goal>weave</goal> </goals> <configuration> <persistenceXMLLocation>META-INF/persistence.xml</persistenceXMLLocation> <logLevel>FINE</logLevel> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa</artifactId> <version>${eclipselink.version}</version> </dependency> </dependencies> </plugin> </plugins> 

See also: EclipseLink - Configuring Static Weaving

0
source

Source: https://habr.com/ru/post/1400138/


All Articles