将maven与第三方提供的DLL一起使用并管理DLL的名称 [英] Using maven with DLL from third party and managing the name of the DLL
问题描述
我有一个Maven项目,正在使用nativedependencies-maven-plugin
( https://github.com/fmarot/nativedependencies-maven )来管理DLL.
I have a maven project and am using the nativedependencies-maven-plugin
(https://github.com/fmarot/nativedependencies-maven) to manage the DLL.
该DLL来自第三方,并且具有以下结构.假设JAR文件的名称为abc.jar
,相应的DLL为abcxyz.dll
,其中xyz是不带句点的版本号.因此,如果版本为12.6.1,则DLL命名为abc1261.dll
.如果第三方将其产品更新到版本12.7.0,则他们将发布新的JAR abc.jar
和新的DLL abc1270.dll
.
The DLL is from a third party, and has the following structure. Let's say that the name of the JAR file is abc.jar
and the corresponding DLL is abcxyz.dll
, where xyz is the version number without periods. So if the version is 12.6.1, the DLL is named abc1261.dll
. If the third party updates their product to version 12.7.0, they issue a new JAR abc.jar
and a new DLL abc1270.dll
.
我将JAR存储在本地存储库中,然后反映在存储库中的JAR的名称为abc-x.y.z.jar
.我将分类器放在称为natives-abc
的DLL上,并且存储库中的DLL名称(一旦部署)为abc-x.y.z-natives-abc.dll
.当我构建项目时,abc-x.y.z-natives-abc.dll
然后由nativedependencies-maven-plugin
正确复制到target/natives
文件夹中.
I am storing the JAR in a local repository, and the name of the JAR as reflected in the repository is then abc-x.y.z.jar
. I put a classifier on the DLL called natives-abc
, and the name of the DLL in the repository (once deployed) is abc-x.y.z-natives-abc.dll
. When I build the project, abc-x.y.z-natives-abc.dll
is then properly copied over to the target/natives
folder by the nativedependencies-maven-plugin
.
当我从Eclipse运行项目时,它失败了,因为JAR正在寻找abcxyz.dll
而不是abc-x.y.z-natives-abc.dll
.如果将abc-x.y.z-natives-abc.dll
复制到target/natives
文件夹中的abcxyz.dll
中,则一切正常,因此我知道java.library.path
的设置正确,我也已通过使用jinfo
工具检查该过程来验证这一点.
When I run the project from Eclipse, it fails, because the JAR is looking for abcxyz.dll
and not abc-x.y.z-natives-abc.dll
. If I copy abc-x.y.z-natives-abc.dll
into abcxyz.dll
in the target/natives
folder, then everything works, so I know that the java.library.path
is getting set correctly, which I have also verified by inspecting the process using the jinfo
tool.
我需要的是一旦DLL从本地存储库复制到target/natives
后就被重命名.我不知道如何让Maven做到这一点.
What I need is for the DLL to get renamed once it is copied from the local repository into target/natives
. I can't figure out how to make maven do that.
我想做的是在本地存储库中使用不同版本的abc.jar
和abcxyz.dll
,然后只需更改pom.xml
文件中的<version>
标记以引用不同的版本.部署中的JAR文件的名称无关紧要,但它与DLL的名称相关,因为第三方针对特定版本的JAR文件会查找与该版本相对应的特定DLL名称.
What I want to do is have different versions of abc.jar
and abcxyz.dll
in the local repository, and then just change the <version>
tags in the pom.xml
file to refer to different versions. The name of the JAR file in deployment isn't relevant, but it's associated DLL name is relevant because the JAR file from the third party for a specific version looks for a specific DLL name corresponding to the version.
推荐答案
此处是nativedependencies-maven-plugin
的维护者.
我不确定我是否完全理解,但我认为我有解决方案:
如果要在3 rd 参与者提供的.jar(而不是.dll)库中部署/安装(本地或非本地),那么Maven将在获得此依赖关系并将其解压缩时(带有nativedependency-maven-plugin
),它将保持其内.dll
的名称不变.因此,您的代码(或第三方代码)将在运行时正确找到它.
I'm not sure I understand completely but I think I have a solution:
if you were to deploy/install in you repo (local or not) the .jar (not the .dll) provided by your 3rd party, then when Maven will get this dependency and unzip it (with the nativedependency-maven-plugin
), it will keep untouched the name of the .dll
inside it. So your code (or the 3rd party code) will correctly find it at runtime.
如果您自己的代码加载了DLL,我建议将DLL重命名为一个唯一的名称,而不使用该版本,以简化过程.希望对您有所帮助.
If your own code loads the DLL, I'd have suggested to rename the DLL to a unique name without the version to simplify the process. Hope it helps.
这篇关于将maven与第三方提供的DLL一起使用并管理DLL的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!