maven是否有能力将单个* .dll打包到没有任何来源的jar?

时间:2012-04-17 12:43:43

标签: java maven dll jar jacob

我想将* .dll作为第三方库添加到我的存储库中,在打包过程中只需将它们打包到* .jar,签名并复制到某个特定文件夹。


签名和处理工作做得很好并且工作正常(正如预期的那样使用maven-dependency-plugin和maven-jarsigner-plugin)。但我没有找到任何方法来自动将单个dll打包到jar(没有像maven-assembly-plugin那样的任何来源)。


我看到的解决方案:添加到我的存储库而不是“纯”的dll,但已经打包到jar lib(由我自己打包)......但这不是一个好主意,我猜)

2 个答案:

答案 0 :(得分:1)

我建议您通过maven-assembly-plugin将您的dll打包为zip存档,并让该模块将zip存档部署为您常用的pom。该项目的包装应该是pom而不是默认值。 如果我下载一个jar并在其中找到dll,我会有点困惑, 但如果您愿意,可以通过maven-assembly-plugin创建jar或使用maven-jar-plugin。

答案 1 :(得分:1)

听起来你已成功检索到.dll(带有依赖插件)并签名(jarsigner插件),它位于${project.build.directory}(默认为target)的某个位置。

如果这是正确的,请尝试一下:

  • 将项目的packaging定义为jar
  • 检索dll
  • 确保jarsigner:sign目标与prepare-package阶段绑定。它默认绑定到package,我们需要确保在jarsigner:sign之前运行jar:jar

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.2</version>
    <executions>
      <execution>
        <id>sign</id>
        <phase>prepare-package</phase>       <!-- important -->
        <goals>
          <goal>sign</goal>
        </goals>
      </execution>
    </executions>
    </plugin>
    
  • 配置jar插件以包含已签名的dll

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
      <execution>
        <!-- using this ID merges this config with default -->
        <!-- So it should not be necessary to specify phase or goals -->
        <!-- Change classes directory because it will look in target/classes 
             by default and that probably isn't where your dlls are.  If
             the dlls are in target then directoryContainingSignedDlls is
             simply ${project.build.directory}. -->
        <id>default-jar</id>   
        <configuration>
          <classesDirectory>directoryContainingSignedDlls</classesDirectory>
          <includes>
            <include>**/*.dll</include>
          </includes>
        </configuration>
      </execution>
    </executions>
    </plugin>
    
  • 现在,运行mvn clean package会给你一个包含已签名dll的jar。

  • 如果JACOB需要清单配置,则docs解释如何执行此操作。
祝你好运!