首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven shade plugin Packaging DLL

Maven shade plugin Packaging DLL
EN

Stack Overflow用户
提问于 2014-06-03 17:25:09
回答 2查看 1.1K关注 0票数 19

我必须在我的项目中添加一个JNI模块。

我在Maven中将模块安装为两个不同的工件: jar库:

代码语言:javascript
复制
mvn install:install-file -DgroupId=com.test -DartifactId=ssa -Dversion=1.0 -Dpackaging=jar -Dfile=ssa.jar

和带有DLL的运行时库

代码语言:javascript
复制
mvn install:install-file -DgroupId=com.sirio -Dpackaging=ddl -DartifactId=ssa-runtime -classifier=windows-x86 -Dversion=1.0 -Dfile=SSADll.dll

在我的maven项目中,我添加了以下依赖项:

代码语言:javascript
复制
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>ssa</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>com.test</groupId>
        <artifactId>ssa-runtime</artifactId>
        <classifier>windows-${arch}</classifier>
        <type>dll</type>
        <version>1.0</version>
        <scope>runtime</scope>
    </dependency>

我的问题是,当我运行shade插件目标来创建一个带有依赖项的jar时,我得到了错误:

代码语言:javascript
复制
Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project ....: Error creating shaded jar: error in opening zip file sirio\ssa-runtime\1.0\ssa-runtime-1.0-windows-x86.dll 

我怎样才能告诉shade插件不要解压dll?

EN

回答 2

Stack Overflow用户

发布于 2021-07-30 20:42:17

也许你需要的是以不同的方式打包。使用您使用的所有java类和库生成带有阴影的jar,然后将该jar和DLL打包到一个要发布的Zip文件中。为此,您可以使用带有zip描述符的maven-assembly-plugin,如下所示:

在你的pom.xml

代码语言:javascript
复制
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>zip.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

zip.xml文件中:

代码语言:javascript
复制
    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
        <id>release</id>
        <formats>
            <format>zip</format>
        </formats>
        <fileSets>
            <fileSet>
                <directory>target</directory>
                <includes>
                    <include>myapp.jar</include>
                </includes>
                <outputDirectory>/</outputDirectory>
            </fileSet>
        </fileSets>
        <files>
            <file>
                <source>your.dll</source>
                <fileMode>0644</fileMode>
            </file>
        </files>
    </assembly>

这样你就有了你需要在这个压缩包中释放的所有东西。我不知道这是否是最好的解决方案,但也许它解决了您的用例的问题。

票数 1
EN

Stack Overflow用户

发布于 2019-04-18 14:56:38

这个解决方案适用于我的JavaFX-OpenCV项目

  1. 将不包含DLL文件的项目打包。
  2. DLL文件复制并粘贴到jar文件目录中。
  3. 现在可以运行应用程序,因为所有DLL文件现在都位于jar应用程序的类路径上。<代码>H29<代码>G210

您的目录应如下所示:

/target/application.jar

/target/your_DLL_files.dll

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24011527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档