Use this option to weave all applicable class files at build time so that you can deliver pre-woven class files. Consider this option to weave all applicable class files at build time so that you can deliver prewoven class files. By doing so, you can improve application performance by eliminating the runtime weaving step required by dynamic weaving (see [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Dynamic Weaving|Configuring Dynamic Weaving]]).

+

Use static weaving to weave all applicable class files at build time so that you can deliver pre-woven class files. Consider this option to weave all applicable class files at build time so that you can deliver prewoven class files. By doing so, you can improve application performance by eliminating the runtime weaving step required by dynamic weaving (see [[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Dynamic Weaving|Configuring Dynamic Weaving]]).

−

In addition, consider using dynamic weaving to weave in Java environments where you cannot configure an agent.

+

In addition, consider using static weaving to weave in Java environments where you cannot configure an agent.

−

Prior to weaving, you must configure your persistence unit to be understood by EclipseLink. There are two basic configurations:

+

==Prerequisite: Organize/Package Files==

+

Prior to weaving, you must package your persistence unit in either of the following configurations:

−

==Configuration Using a Jar File==

+

* JAR file, as specified in the JPA 2.0 specification.{{EclipseLink_Spec

−

This is the configuration specified in the JPA 2.0 specification. Requirements are:

+

|link=http://jcp.org/en/jsr/detail?id=220

−

* Classes stored at the base in directories based on their package structure

+

|section=Section 11.1.18 "Persistence Unit Packaging"}}

−

* A <tt>META-INF</tt> directory containing the <tt>persistence.xml</tt> file. Note: Using the persistenceunitinfo setting below, you can avoid this requirement.

+

−

For example, <tt>mypersitenceunit.jar</tt> could contain

+

* Exploded directory structure

+

+

In both cases, the requirements are:

+

+

* Classes must be stored at the base in directories based on their package structure

+

* There must be a <tt>META-INF</tt> directory that contains the <tt>persistence.xml</tt> file. <br/>Note: You can use the <tt>persistenceinfo</tt> setting on the <tt>weave</tt> Ant task, as described in the [[#Table 19-31|EclipseLink weave Ant Task Attributes]] table, below, to specify a different location.

+

+

For example, when using a JAR file, <tt>mypersitenceunit.jar</tt> could contain the following:

* <tt>mypackage/MyEntity1.class</tt>

* <tt>mypackage/MyEntity1.class</tt>

* <tt>mypackage/MyEntity2.class</tt>

* <tt>mypackage/MyEntity2.class</tt>

Line 24:

Line 31:

* <tt>META-INF/persistence.xml </tt>

* <tt>META-INF/persistence.xml </tt>

−

{{EclipseLink_Spec

+

For example, If your base directory is c:/classes, the exploded directory structure would look as follows:

'''Note:''' If <tt>source</tt> and <tt>target</tt> point to the same location and, if the <tt>source</tt> is a directory (not a JAR file), EclipseLink will weave in place. If <tt>source</tt> and <tt>target</tt> point to different locations, or if the <tt>source</tt> is a JAR file (as the [[#Example 19-37|EclipseLink weave Ant Task]] example shows), EclipseLink cannot weave in place.

+

|}

+

<br></li>

+

<li> Configure the <tt>weave</tt> task with an appropriate <tt><classpath></tt> element, as the [[#Example 19-37|EclipseLink weave Ant Task]] example shows, so that EclipseLink can load all required source classes.</li>

+

<li> Execute the Ant task using the command line that this example shows.<br>In this example, the <tt>weave</tt> Ant task is in the <tt>build.xml</tt> file:<br>

'''Note:''' You must specify the <tt>eclipselink.jar</tt> file (the JAR that contains the EclipseLink <tt>weave</tt> Ant task) using the Ant command line <tt>-lib</tt> option instead of using the <tt>taskdef</tt> attribute <tt>classpath</tt>.

<br>The following example shows how to use the <tt>StaticWeave</tt> class on Windows systems. The [[#Table 19-32|EclipseLink StaticWeave Class Command Line Arguments]] table lists the arguments of this class.<br>

Specifies the location of the <tt>persistence.xml</tt> file if it is not at the same location as the source (see <tt>-classpath</tt>) Note: EclipseLink will look in a META-INF directory at that location for persistence.xml.

+

| headers="r2c1-t50 r1c3-t50" align="left" | <br>

+

| headers="r2c1-t50 r1c4-t50" align="left" |

+

Optional

+

|- align="left" valign="top"

+

| id="r3c1-t50" headers="r1c1-t50" align="left" |

+

<tt>-classpath</tt>

+

| headers="r3c1-t50 r1c2-t50" align="left" |

+

Specifies the location of the Java source files to weave: either a directory or a JAR file. For Windows systems, use delimiter <tt>" ; "</tt>, and for Unix, use delimiter <tt>" : "</tt>.

+

+

If the <tt>persistence.xml</tt> file is not in this location, you must specify the location of the <tt>persistence.xml</tt> using the <tt>-persistenceinfo</tt> attribute.

+

| headers="r3c1-t50 r1c3-t50" align="left" | <br>

+

| headers="r3c1-t50 r1c4-t50" align="left" |

+

Required

+

|- align="left" valign="top"

+

| id="r4c1-t50" headers="r1c1-t50" align="left" |

+

<tt>-log</tt>

+

| headers="r4c1-t50 r1c2-t50" align="left" |

+

Specifies a logging file.

+

| headers="r4c1-t50 r1c3-t50" align="left" |

+

+

| headers="r4c1-t50 r1c4-t50" align="left" |

+

Optional

+

|- align="left" valign="top"

+

| id="r5c1-t50" headers="r1c1-t50" align="left" |

+

<tt>-loglevel</tt>

+

| headers="r5c1-t50 r1c2-t50" align="left" |

+

Specifies the amount and detail of log output.

+

+

Valid <tt>java.util.logging.Level</tt> values are as follows:

+

* <tt>OFF</tt>

+

* <tt>SEVERE</tt>

+

* <tt>WARNING</tt>

+

* <tt>INFO</tt>

+

* <tt>CONFIG</tt>

+

* <tt>FINE</tt>

+

* <tt>FINER</tt>

+

* <tt>FINEST</tt>

+

+

For more information, see [[Introduction%20to%20EclipseLink%20Sessions%20(ELUG)#Logging|Logging]].

+

| headers="r5c1-t50 r1c3-t50" align="left" |

+

<tt>Level.OFF</tt>

+

| headers="r5c1-t50 r1c4-t50" align="left" |

+

Optional

+

|- align="left" valign="top"

+

| id="r6c1-t50" headers="r1c1-t50" align="left" |

+

<tt><nowiki><source></nowiki></tt>

+

| headers="r6c1-t50 r1c2-t50" align="left" |

+

Specifies the location of the Java source files to weave: either a directory or a JAR file.

+

+

If the <tt>persistence.xml</tt> file is not in this location, you must specify the location of the <tt>persistence.xml</tt> using the [[#-persistenceinfo|<tt>-persistenceinfo</tt>]] attribute.

'''Note:''' If <tt><nowiki><source></nowiki></tt> and <tt><target></tt> point to the same location and if the <tt><nowiki><source></nowiki></tt> is a directory (not a JAR file), EclipseLink will weave in place. If <tt><nowiki><source></nowiki></tt> and <tt><target></tt> point to different locations, or if the <tt>source</tt> is a JAR file (as the [[#Example 19-39| Executing StaticWeave on the Command Line]] example shows), EclipseLink cannot weave in place.

+

|}

+

<br>

+

+

===Step 2: Configure persitence.xml===

+

Configure your <tt>persistence.xml</tt> file with a <tt>[[#eclipselink.weaving|eclipselink.weaving]]</tt> extension set to <tt>static</tt>, as this example shows:<br>

+

+

<span id="Example 19-40"></span>

+

+

''''' Setting eclipselink.weaving in the persistence.xml File'''''

+

<div class="pre">

+

<persistence>

+

<persistence-unit name="HumanResources">

+

<class>com.acme.Employee</class>

+

...

+

<properties>

+

+

<property

+

name="eclipselink.weaving"

+

value="static"

+

>

+

</properties>

+

</persistence-unit>

+

</persistence>

+

</div>

+

<br>

+

For more information, see the [[#Table 19-16|EclipseLink JPA Persistence Unit Properties for Customization and Validation]] table.

Configuring Static Weaving

Use static weaving to weave all applicable class files at build time so that you can deliver pre-woven class files. Consider this option to weave all applicable class files at build time so that you can deliver prewoven class files. By doing so, you can improve application performance by eliminating the runtime weaving step required by dynamic weaving (see Configuring Dynamic Weaving).

In addition, consider using static weaving to weave in Java environments where you cannot configure an agent.

Prerequisite: Organize/Package Files

Prior to weaving, you must package your persistence unit in either of the following configurations:

JAR file, as specified in the JPA 2.0 specification.

For more information, see Section 11.1.18 "Persistence Unit Packaging" in the JPA Specification.

Exploded directory structure

In both cases, the requirements are:

Classes must be stored at the base in directories based on their package structure

There must be a META-INF directory that contains the persistence.xml file. Note: You can use the persistenceinfo setting on the weave Ant task, as described in the EclipseLink weave Ant Task Attributes table, below, to specify a different location.

For example, when using a JAR file, mypersitenceunit.jar could contain the following:

mypackage/MyEntity1.class

mypackage/MyEntity2.class

mypackage2/MyEntity3.class

META-INF/persistence.xml

For example, If your base directory is c:/classes, the exploded directory structure would look as follows:

Note: If source and target point to the same location and, if the source is a directory (not a JAR file), EclipseLink will weave in place. If source and target point to different locations, or if the source is a JAR file (as the EclipseLink weave Ant Task example shows), EclipseLink cannot weave in place.

Configure the weave task with an appropriate <classpath> element, as the EclipseLink weave Ant Task example shows, so that EclipseLink can load all required source classes.

Execute the Ant task using the command line that this example shows.In this example, the weave Ant task is in the build.xml file: EclipseLink weave Ant Task Command Line

ant -lib C:\eclipselink.jar -f build.xml weave

Note: You must specify the eclipselink.jar file (the JAR that contains the EclipseLink weave Ant task) using the Ant command line -lib option instead of using the taskdef attribute classpath.

Specifies the location of the persistence.xml file if it is not at the same location as the source (see -classpath) Note: EclipseLink will look in a META-INF directory at that location for persistence.xml.

Optional

-classpath

Specifies the location of the Java source files to weave: either a directory or a JAR file. For Windows systems, use delimiter " ; ", and for Unix, use delimiter " : ".

If the persistence.xml file is not in this location, you must specify the location of the persistence.xml using the -persistenceinfo attribute.

Specifies the location of the Java source files to weave: either a directory or a JAR file.

If the persistence.xml file is not in this location, you must specify the location of the persistence.xml using the -persistenceinfo attribute.

Required

<target>

Specifies the output location: either a directory or a JAR file.

Required

Note: If <source> and <target> point to the same location and if the <source> is a directory (not a JAR file), EclipseLink will weave in place. If <source> and <target> point to different locations, or if the source is a JAR file (as the Executing StaticWeave on the Command Line example shows), EclipseLink cannot weave in place.

Step 2: Configure persitence.xml

Configure your persistence.xml file with a eclipselink.weaving extension set to static, as this example shows: