JF *_*ier 7 java persistence jar maven
我们正在制作带有大量罐子的耳朵文件.其中一些包含persistence.xml文件,用于定义引用其他jar的持久性单元
<jar-file>other.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)
现在我们计划将来使用Maven,jar名称现在包含版本号.对于上述机制来说,这是一个巨大的问题:other.jar我们需要指定other-1.2.3.jar.但是在构建jar时无法知道正确的版本号,因为在构造耳朵时,依赖性中介可以替换other-1.2.3.jar为other-2.3.4.jar使得我在jar的persistence.xml中的引用变得无效.
所以我的问题是:在构建大型ear文件时,如何在Maven中正确管理persistence.xml文件?
编辑:
让我尝试构建一个小例子,让我的观点更加清晰:
让我们first-ejb-1.0.0.jar依靠other-1.2.3.jar并second-ejb-1.0.0.jar依赖other-2.3.4.jar.双方first-ejb-1.0.0.jar并second-ejb-1.0.0.jar包含有一个persistence.xml中<jar-file>条目.first-ejb-1.0.0.jar指向other-1.2.3.jar并second-ejb-1.0.0.jar指向other-2.3.4.jar.到现在为止还挺好.
现在我从first-ejb-1.0.0.jar和建立一个耳朵second-ejb-1.0.0.jar.依赖关系已解决,但只有一个other-*.jar可以包含在耳中.比如,我们的依赖调解选择other-2.3.4.jar.然后first-ejb-1.0.0.jar有一个死的<jar-file>条目,指向一个不存在的jar.
因此,就像您自己所说的那样,当您构建 EAR 时,您的工件就已构建,并且jar-file已经定义并且无法更改。因此,有两种选择:
jar-file必须是特定版本 - 不允许使用其他版本jar-file可以是任何版本 - 从 jar 名称中排除版本1.严格版本
您可以使用single-version range强制 Maven 仅考虑特定版本的依赖项:
<dependency>
<groupId>my.company</groupId>
<artifactId>persistence</artifactId>
<!-- require specifically this version -->
<version>[1.0.2]</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
2.从jar名称中排除版本
您可以使用任何名称将 jar 添加到 EAR,即使没有版本:
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<modules>
<ejbModule>
<groupId>my.company</groupId>
<artifactId>persistence</artifactId>
<!-- rename artifact in ear -->
<bundleFileName>persistence.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
980 次 |
| 最近记录: |