Maven: Export jar with 3rd party jars added to classpath in manifest

I am developing a Java maven project with Eclipse and want to export a jar that includes all the referenced libraries . These referenced libraries fall into one of these two categories:

  • They are explicit (or implicit) dependencies inpom.xml

  • I have several libraries not available as maven artifacts and placed them in / lib (and added them to build path in Eclipse)

There maven-assembly-plugin

that works great for 1). However, I cannot find a maven plugin that also includes non-maven dependencies, eg. "all jars in /lib"

...

Then there is an Eclipse plugin FatJar

that works but hasn't been updated since 2009, so it seems that it is not supported. I also prefer the export method, which I can specify directly to pom.xml

.

Can anyone point me to a plugin maven

or the like to export all referenced libraries, including from example 2)? It only needs to include embed them in the jar and reference them in the explicit classpath.

Thank!

+1


source to share


2 answers


I think the best way to handle this is to include your custom libraries in your local maven repository. Now you can include your libraries as maven dependencies and you can export all your dependencies specified in your pom using maven-assembly-plugin.

Here is a tutorial on how to put your libraries into a local repository in maven to use in your pom. http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/



And in your pom.xml:

<!-- setup jar manifest to executable with dependencies -->
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
      <manifest>
        <mainClass>your.main.class</mainClass>
      </manifest>
    </archive>
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
       <goal>single</goal>
      </goals>  
    </execution>
  </executions>
</plugin>

      

+4


source


This looks like a challenge for Tycho . It is a set of maven plugins that allows you to create eclipse plugins with maven. Tycho views records as assembly dependencies.



However, I don't know how to package all these dependencies in one jar. It may also be against the osgi specification. But if you want to ignore osgi, you can just try the jar-with-dependencies build.

0


source







All Articles