【问题标题】:How to enable static weaving in eclipseLink with remote persistence.xml using Maven?如何使用 Maven 在 eclipseLink 中使用远程 persistence.xml 启用静态编织?
【发布时间】:2017-05-24 16:45:22
【问题描述】:

我有一个单独的 jar,其中包含 persistence.xml。此 jar 已作为依赖项添加到具有实体的 jar 的父 pom 中。我想启用静态编织。 根据EclipseLink documentation,我可以将persistenceXMLLocation 指定为配置。但是,这个位置应该是我的 persistence.xml 的绝对文件路径还是它在存储库中的路径。另外,如何在启用编织的情况下构建我的实体 jar?执行此插件的 maven 命令是什么?

以下是我在执行插件时遇到的错误:

    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

在这里,它在实体项目的类路径中寻找 persistence.xml 文件。

我使用的 mvn 命令是:

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

插件是:

<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 版本:2.5.1-RC1

我有什么遗漏吗?

【问题讨论】:

  • 最后一个 URL 分隔符 - D:\BRIDGE\BRIDGE-PARTIAL\DB\persistence-config\src\main\resources\META-INF/persistence.xml
  • @Rima:那行不通。无论如何,在错误中,它显示它试图从主项目的资源文件夹中获取 persistence.xml

标签: java jpa eclipselink


【解决方案1】:

我也尝试过像你这样的绝对路径,但没有成功。

我认为外部资源文件不是最佳做法。但是您可以使用 maven-resources-plugin:2.6:resources 在 process-resources 阶段将资源复制到 /target/classes。

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


而 staticweave-maven-plugin:1.0.0:weave 在流程类阶段运行。所以persistence.xml在这个阶段位于/target/classes/META-INF/persistence.xml。

使用相对路径并设置

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

在staticweave-maven-plugin的配置中。

【讨论】:

    猜你喜欢
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2019-07-22
    • 1970-01-01
    • 2019-08-05
    • 2015-04-13
    相关资源
    最近更新 更多