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

时间:2012-07-20 11:58:12

标签: maven maven-2 m2e eclipse-juno

我在我的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> 

3 个答案:

答案 0 :(得分:9)

这里的问题是jar-with-dependencies描述符。描述符unpacks将所有依赖项放入目录中,并将此目录打包到新的JAR文件中。但是,它无法解压缩DLL文件(即“No such archiver”错误消息)。要使其正常工作,您需要定义自己的程序集描述符:

<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-assembly-plugin的配置如下所示:

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

答案 1 :(得分:0)

这里有一条信息:Maven Dll Dependency Problem。  要解决此问题,请从程序集中排除dll:

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

上次我不得不创建一个带有依赖项的可执行jar,我将它们放在jar目录下的jar中。 DLL必须是:

  • 在应用程序类路径中(如服务器的server / lib)
  • 或在OS类路径中(例如C:\ Windows \ system32)

在阅读了你的pom和dependecy文件集后,我可能会更准确:)

答案 2 :(得分:0)

为了增加Stefan的答案,我不认为你想为你的这个项目做jar-with-dependencies包装。你应该看看使用bin包装之一(如.zip或tar.gz)