Search code examples
javamavendlljarjacob

Does maven have an ability to pack single *.dll to jar without any sources?


I'd like to add *.dlls as third party libs to my repository and during packaging process just pack them to *.jar, sign them and copy to some specific folder.


Signing and coping are well done and work correctly (as expected by using maven-dependency-plugin and maven-jarsigner-plugin). But I didn't find any method to automatically pack single dll to jar (without any sources like maven-assembly-plugin does).


Solution that I see by the time: add to my repository not a "pure" dll, but already packed to jar lib (packed by myself)... but it's not a good idea, I guess)


Solution

  • It sounds like you've successfully retrieved your .dll (with dependency plugin) and signed it (jarsigner plugin), and it's somewhere in your ${project.build.directory} (which defaults to target).

    If that's correct, give this a try:

    • Define the packaging of your project as jar
    • Retrieve dlls
    • Make sure the jarsigner:sign goal is bound to the prepare-package phase. It binds to package by default and we need to ensure jarsigner:sign runs before 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>
      
    • Configure the jar plugin to include the signed dll(s)

      <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>
      
    • Now, running mvn clean package should give you a jar containing your signed dlls.

    • If JACOB requires manifest config there are docs explaining how to do this.

    Good luck!