首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Maven-单目标在Jar中打包Dll

使用Maven-单目标在Jar中打包Dll
EN

Stack Overflow用户
提问于 2012-07-20 11:58:11
回答 3查看 9.7K关注 0票数 12

我在maven项目中添加了一个DLL作为依赖项,如下所示:

代码语言:javascript
复制
<dependency>
  <groupId>com.test.dll</groupId>
  <artifactId>myDll</artifactId>
  <version>0.1</version>
  <type>dll</type>
</dependency>

当我尝试执行maven:install

它给了我这个错误:

代码语言:javascript
复制
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-   
beta-5:single (jar-with-dependencies) on project testApp: Failed to create 
assembly:    Error adding file-set for 'com.test.dll:myDll:dll:0.1' to archive: Error 
 adding archived file-set. PlexusIoResourceCollection not found for: C:\Users\USER\.m2
 \repository\com\test\dll\myDll\0.1\myDll-0.1.dll: No such archiver: 'dll'

我在这里做错什么了?

更新

代码语言:javascript
复制
 <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>   
        <executions>
        <execution>
        <goals>
            <goal>sign</goal>
        </goals>
        </execution>
       </executions>
       <configuration>
        <keystore>src/main/keystore/mykey.keystore</keystore>
        <alias>aliasname</alias>
        <storepass>passw0rd</storepass>                  
        <verify>true</verify>

    </configuration>        
    </plugin>               
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>      
        <executions>
            <execution>
                <id>jar-with-dependencies</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>single</goal>
                </goals>       
            <configuration>
            <archive>
                <manifest>

                </manifest>
            </archive>              
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>           
            <appendAssemblyId>false</appendAssemblyId>
        </configuration>
    </execution>     
  </executions>      
  </plugin>   
 </plugins> 
EN

回答 3

Stack Overflow用户

发布于 2012-07-30 19:42:10

这里的问题是jar-with-dependencies描述符。描述符解包将所有依赖项打包到一个目录中,并将该目录打包到一个新的JAR文件中。但是,它不能解压缩DLL文件(这是“没有这样的存档”错误消息)。要使此工作正常,您需要定义自己的程序集描述符:

代码语言:javascript
复制
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

  <id>assembly-with-dll</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <!-- package the regular dependencies -->
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <unpack>true</unpack>
      <scope>runtime</scope>
      <!-- exclude the DLL -->
      <excludes>
        <exclude>com.example:my-dll</exclude>
      </excludes>
    </dependencySet>
    <!-- package the DLLs -->
    <dependencySet>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>com.example:my-dll</include>
      </includes>
    </dependencySet>
  </dependencySets>
</assembly>

如果上面的描述符位于src/main/assembly中,那么maven程序集插件的配置如下所示:

代码语言:javascript
复制
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <executions>
        <execution>
          <id>jar-with-dependencies</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
            <appendAssemblyId>false</appendAssemblyId>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
票数 9
EN

Stack Overflow用户

发布于 2012-07-22 08:47:38

这里有一条信息:Maven Dll依赖问题。若要解决此问题,请从程序集中导出dll:

代码语言:javascript
复制
<excludes>
    <exclude>*:dll*</exclude>
</excludes>

上一次我必须创建一个带有依赖项的可执行jar时,我将它们放到了lib目录中的jar之外。DLL必须是:

  • 无论是在应用程序类路径中(就像服务器/lib中的服务器)
  • 或者在OS类路径中(例如C:\Windows\system32 32)

在阅读了您的pom和信任文件集之后,我可能能够更准确地:)

票数 0
EN

Stack Overflow用户

发布于 2012-07-31 04:23:47

为了补充Stefan的答案,我不认为您想为您的这个项目做一个jar-with-dependencies打包。您应该考虑使用一个箱子包(比如.zip或tar.gz)。

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

https://stackoverflow.com/questions/11578903

复制
相关文章

相似问题

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