16

I am looking for a JAR file generator fitting these requirements:

  • Able to create jar files containing other jar files
  • Makes creation and maintenance of manifest files easy.
5
  • 2
    What kind of complexities are we talking about? All of my .jar files (and their manifests) are built automatically by Apache Maven as a part of the build process. Commented Feb 4, 2014 at 23:15
  • PKZIP? (Or Info-ZIP…)
    – mirabilos
    Commented Feb 4, 2014 at 23:24
  • @Darth Android Actually, I am in a position where I quite often have to use ant for my projects
    – demongolem
    Commented Feb 5, 2014 at 1:51
  • @demongolem: What kind of jar are you trying to create exactly? List all of the "difficulties".
    – Nicolas Raoul
    Commented Feb 10, 2014 at 8:33
  • @Nicolas Raoul For one, classpath issues when packaging jar inside of my jar. That use case in itself gets mangled most of the time.
    – demongolem
    Commented Feb 10, 2014 at 14:10

3 Answers 3

10

For creating fat jars jarjar is a brilliant tool since it is easy to use, well maintained and has a good plugin support. It is also recommended by many libraries that typically require repacking such as ASM. Otherwise, build managers such as Maven or Gradle should offer you the functionality you are looking for out of the box. You should be able to pack recources in dependency of build profiles.

2

If you're looking to package your application together with its library JARs as one JAR file, you might consider the BSD-licensed One-Jar. One-Jar uses a custom classloader to load from JARs inside your main JAR file, while (based on its documentation) jarjar flattens all your classes into just one JAR file (no inner JARs), modifying class files as necessary.

Depending on your application, One-Jar's approach may work better (or worse) than jarjar's.

0

I think Maven is the tools that can do everything (with some configuration).

Exemple: I have a folder (./lib) where I have all my JAR files, I just have the following small pom.xml file like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.mycompany.test</groupId>
    <artifactId>bigjar</artifactId>
    <packaging>jar</packaging>

    <version>1.0-SNAPSHOT</version>

    <url>http://www.mycompany.com</url>

    <prerequisites>
        <maven>3.1.0</maven>
    </prerequisites>

    <!-- Put external dependencies here -->
    <dependencies>

    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>
        <resources>
            <resource>
                <directory>lib</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</project>  

Just run mvn clean install, and then you have all your lib/*.jar files in a new JAR.

If you need external Jars, you can just add it as a new dependency (in the section).

You want to manage the Manifest.MF, just have a look in this article, they explain how to use the maven-jar-plugin. Official documentation here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.