How to enable static weaving in eclipseLink with r

2019-07-23 20:44发布

问题:

I have a separate jar which contains the persistence.xml. This jar has been added as a dependency in the parent pom of the jar which has the entities. I want to enable static weaving. According to EclipseLink documentation, I can specify the persistenceXMLLocation as a configuration. However, should this location be an absolute file path of my persistence.xml or its path in a repository. Also how can I build my entities jar with weaving enabled? What would be the maven command to execute this plugin?

Following is the error I get when the plugin is executed:

    Failed to execute goal de.empulse.eclipselink:staticweave-maven-plugin:1.0.0:weave (default-cli) on project BRBASE-techl-entities: Execution default-cli of goal de.empulse.eclipselink:staticweave-maven-plugin:1.0.0:weave failed:
[ERROR] Exception Description: An exception was thrown while trying to load persistence unit at url: file:/D:/BRIDGE/BRIDGE-PARTIAL/BRBASE_Branch_selective_fetch/src/core/techl/entities/target/classes/
[ERROR] Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.5.1.v20130824-981335c): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
[ERROR] Exception Description: An exception was thrown while processing persistence.xml from URL: file:/D:/BRIDGE/BRIDGE-PARTIAL/BRBASE_Branch_selective_fetch/src/core/techl/entities/target/classes/
[ERROR] Internal Exception: java.net.MalformedURLException: NullPointerException

Here, its looking for the persistence.xml file in the entities project's classpath.

The mvn command I am using is :

de.empulse.eclipselink:staticweave-maven-plugin:weave

The plugin is :

<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>
                            <logLevel>FINE</logLevel>
                            <persistenceXMLLocation>D:\BRIDGE\BRIDGE-PARTIAL\DB\persistence-config\src\main\resources\META-INF\persistence.xml</persistenceXMLLocation>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.persistence</groupId>
                        <artifactId>org.eclipse.persistence.jpa</artifactId>
                        <version>2.5.1-RC1</version>
                    </dependency>
                    <dependency>
                        <groupId>com.mindtree.bridge.platform.db</groupId>
                        <artifactId>BRDB-persistence-config</artifactId>
                        <version>${db.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

EclipseLink version used : 2.5.1-RC1

Is there something I am missing?

回答1:

I also tried it with absolulte path like you and it is not worked.

I think the external resource files are not the best practise. But you can do it with maven-resources-plugin:2.6:resources to copy resources to <#maven-module>/target/classes in the process-resources phase.

<resources>
    <!-- ... -->
    <resource>
        <directory>D:/BRIDGE/BRIDGE-PARTIAL/DB/persistence-config/src/main/resources</directory>
        <includes>
            <include>META-INF/persistence.xml</include>
        </includes>
    </resource>
</resources>


And staticweave-maven-plugin:1.0.0:weave runs in the process-classes phase. So the persistence.xml is located in <#maven-module>/target/classes/META-INF/persistence.xml in this phase.

Use relative path and set the

<persistenceXMLLocation>META-INF/persistence.xml</persistenceXMLLocation>

in the configuration of staticweave-maven-plugin.