-->

包中的DLL罐使用Maven-单一目标(Package Dll in Jar using Maven

2019-06-26 10:27发布

我在Maven项目像这种依赖增加了一个DLL:

<dependency>
  <groupId>com.test.dll</groupId>
  <artifactId>myDll</artifactId>
  <version>0.1</version>
  <type>dll</type>
</dependency>

当我尝试执行maven:install

它给我这个错误:

[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'

我到底做错了什么?

更新

 <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> 

Answer 1:

这里的问题是jar-with-dependencies描述。 该描述符解压所有依赖到一个目录,这个目录打包到一个新的JAR文件。 但是,它不能解开一个DLL文件(这是“没有这样的归档程序”的错误消息)。 为了得到这个工作,你需要定义自己的装配描述:

<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 ,行家组装-插件的配置看起来如下:

<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>


Answer 2:

有一条信息在这里: Maven的DLL的依赖性问题 。 为了解决这个问题,从您的装配exlude DLL:

 <excludes> <exclude>*:dll*</exclude> </excludes> 

上次我不得不创建一个依赖可执行的JAR,我把他们赶出了罐子,在lib目录下。 DLL必须是:

  • 无论是在应用的类路径(像服务器/ lib中的服务器)
  • 或OS类路径(C:\ Windows \ System32下的实例)

读你的POM和dependecy文件集之后,我也许能够更准确:)



Answer 3:

要添加到Stefan的回答,我不认为你想要做一个jar-with-dependencies这个项目你们的包装。 你应该看看使用的一个箱子包装(如.zip或tar.gz的)



文章来源: Package Dll in Jar using Maven- single goal