Java 使用 Maven 管理 DLL 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1001774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:07:16  来源:igfitidea点击:

Managing DLL dependencies with Maven

javadllmaven-2java-native-interface

提问by Kris

I have a Java program with Maven managing its dependencies. One of those dependency is a JNI wrapper for another program. Maven takes care of the reference to the relevant JAR file, but I'm left messing around with the DLL file myself.

我有一个 Java 程序,Maven 管理其依赖项。其中一个依赖项是另一个程序的 JNI 包装器。Maven 负责对相关 JAR 文件的引用,但我自己却在处理 DLL 文件。

Is there a good way of having Maven handle the DLL as well? Ideally I would like to have the DLL loaded into our local repository like the JAR file.

有没有让 Maven 处理 DLL 的好方法?理想情况下,我希望将 DLL 像 JAR 文件一样加载到我们的本地存储库中。

采纳答案by sal

Did you try something like this:

你有没有尝试过这样的事情:

<dependency>
    <groupId>com.foo</groupId>
    <artifactId>footron</artifactId>
    <version>4.2</version>
    <scope>runtime</scope>
    <type>dll</type>
</dependency>

You can add them to maven's repository with something like this:

您可以将它们添加到 Maven 的存储库中,如下所示:

mvn install:install-file -Dfile=footron.dll -DgroupId=com.foo -DartifactId=footron  -Dversion=4.2 -Dpackaging=dll -DgeneratePom=true 

Haven't done this for DLLs but something like this should work.

还没有为 DLL 做过这件事,但像这样的事情应该可以工作。

回答by Irv

I found another solution, which is described in the answer to this question: Using maven with DLL from third party and managing the name of the DLL

我找到了另一个解决方案,在这个问题的答案中有描述:Using maven with DLL from third party and management the name of the DLL

Basically, if you put the DLL into a ZIP file, and manage it as a separate dependency, and use the nativedependencies-maven-plugin, then the DLL will get unpacked with the right name.

基本上,如果您将 DLL 放入 ZIP 文件中,并将其作为单独的依赖项进行管理,并使用 . nativedependencies-maven-plugin,那么 DLL 将使用正确的名称解压。