Package Dll in Jar using Maven- single goal

自作多情 提交于 2019-12-04 00:22:48

问题


I have added a DLL in my maven project as dependency like this :

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

When I try to execute maven:install

It is giving me this error:

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

What Am I doing wrong here??

Update

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

回答1:


The problem here is the jar-with-dependencies descriptor. The descriptor unpacks all dependencies into a directory and packages this directory into a new JAR file. However, it cannot unpack a DLL file (that's the "No such archiver" error message). To get this working, you need to define your own assembly descriptor:

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

Provided, that the descriptor above resides in src/main/assembly, the configuration of the maven-assembly-plugin looks as follows:

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



回答2:


There is a piece of information here : Maven Dll Dependency Problem. To solve this issue, exlude dll from your assembly :

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

Last time I had to create a executable jar with dependencies, I put them out of the jar, in a lib directory. DLL must be :

  • either in application classpath (like server/lib for a server)
  • or in the OS classpath (C:\Windows\system32 for instance)

After reading your pom and dependecy file set, I may be able to be more accurate :)




回答3:


To add to Stefan's answer, I don't think you want to do a jar-with-dependencies packaging for this project of yours. You should look at using one of the bin packaging (like .zip or tar.gz)



来源:https://stackoverflow.com/questions/11578903/package-dll-in-jar-using-maven-single-goal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!