Building JAR that includes all its dependencies

前端 未结 5 2112
盖世英雄少女心
盖世英雄少女心 2020-12-06 12:14

This is probably a really fundamental question, but I\'m afraid I don\'t know much about Java and I couldn\'t find the answer anywhere.

I\'m attempting to build an A

相关标签:
5条回答
  • 2020-12-06 12:37

    You would need to depend on classpath attribute in manifest file. This explained well at How to package libraries into my jar using Ant

    0 讨论(0)
  • 2020-12-06 12:40

    When you build a jar you get a JAR containing just your code, and not any dependencies your Jar requires. You could use something like jarjar to combine all the dependencies into one easy to manage Jar file or copy all the depend JARs into a folder for ease of use. It looks like Eclipse has options to also do this kind of thing (see posts above).

    The other option would be to use a dependency management system such as Maven or Ivy. This has a higher learning curve, but for a library it is worthwhile as it will allow users of your library to easy grab all the dependencies. For an end user application then a single distributable is likely a better option (for which you could use Maven or Ivy to internally manage the dependencies and then something like jarjar or Java Web Start to distribute to your end users).

    0 讨论(0)
  • 2020-12-06 12:43

    Select "Extract required libraries into generated JAR" as you do the export.

    Extract required libraries into generated JAR

    Select "Extract required libraries into generated JAR" as you do the export.

    0 讨论(0)
  • 2020-12-06 12:47

    Use File -> Export -> Java -> Runnable JAR file instead from Eclipse.

    The "Extract required libraries into generated JAR" should be what you need.

    0 讨论(0)
  • 2020-12-06 12:51

    Just in case if you're doing with maven. You need to include following plugin.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <properties>
                <property>
                    <name>listener</name>
                    <value>com.example.TestProgressListener</value>
                </property>
            </properties>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id> <!-- this is used for inheritance merges -->
                <phase>package</phase> <!-- bind to the packaging phase -->
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    Read more @ how do I build JAR file with dependencies?

    0 讨论(0)
提交回复
热议问题