Eclipse: How to build an executable jar using ant with external project dependencies?

Klinsman Maia

I am trying to build an executable jar program using a ant script. When the project doesn't have any dependencies it works fine, but when I add another project as dependency, the ant script don't find the classes from this.

I did a simple just to test and understand how it works.

Follow:

Ant script example:

<target name="compile">
    <mkdir dir="${classes.dir}" />
    <javac srcdir="${src.dir}" destdir="${classes.dir}" />
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}" />

    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="*.class" >
        <manifest>
            <attribute name="Main-Class" value="${main-class}" />
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
</target>

My project structure is like this:

AntHelloWorld depends AntTest. My build.xml is in AntHelloWorld and I wanna modify my ant build.xml to works with the project dependency. (I can't post images yet)

I tried to find this and I just saw how to do this with jar dependencies, How to build an executable jar with external jar?

This is my first question in stackoverflow, feel free to inform where can I improve.

KyleM

The javac directive can have subelements that include a classpath. You can put your dependent project's JAR files on the classpath. Consider this example which demonstrates putting JAR files on the classpath:

//This goes inside the javac element     
    <classpath>
         <fileset dir="${dependentProject}/lib">
                <include name="**/*.jar" /> 
         </fileset>
     </classpath>

As a second example, if you want to include class files from your dependent project, and your class files are located in the build directory:

 <classpath>
     <pathelement location="${dependentProject}/build" />
     <fileset dir="${dependentProject}/lib">
            <include name="**/*.jar" /> 
     </fileset>
 </classpath>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Build executable .jar with external .jar dependencies copied in a lib folder

From Dev

Maven: How to include my external jar into build executable jar

From Dev

executable jar with dependencies using maven

From Dev

Multiple executable jar files with different external dependencies from a single project with sbt-assembly

From Dev

How to include an external jar lib in my Ant build

From Dev

Using Maven in Ant for jar dependencies

From Dev

How to build an executable jar from multi module maven project?

From Dev

Maven and Netbeans: how do I build project and get executable jar?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How to include http library in Android Project using M preview in Eclipse ant build

From Dev

External jar not importing in Eclipse Project

From Dev

External jar not importing in Eclipse Project

From Dev

java build ant file with external jar files

From Dev

How to generate Ant and Maven build files for an Eclipse Java project?

From Dev

How to build an executable jar in java

From Dev

Creating jar executable w/ external jar (JXL) in ECLIPSE java

From Dev

Adding external dependencies to ant project (IDEA Android project)

From Dev

Combine java code and dependencies into one jar (executable jar) using maven

From Dev

How to generate a jar with internal dependencies bundled and external dependencies as external jars?

From Dev

How do I refresh project dependencies using Buildship in Eclipse?

From Dev

How to provide Gradle dependencies for Ant build

From Dev

How do I create an executable jar file including dependencies where the main class is in Test, using Maven

From Dev

Spring Boot + Gradle: how to build executable jar

From Dev

Exclude Jar from Ant Build using zipgroupfileset

From Dev

Using cmake for a project with sub/external projects/dependencies

From Dev

How to build jar-file with ant?

From Dev

Eclipse ANT Build.xml create JAR is showing corrupted file

From Dev

Ant to Gradle: Executable JAR conversion

From Java

How do I create an executable fat jar with Gradle with implementation dependencies

Related Related

  1. 1

    Build executable .jar with external .jar dependencies copied in a lib folder

  2. 2

    Maven: How to include my external jar into build executable jar

  3. 3

    executable jar with dependencies using maven

  4. 4

    Multiple executable jar files with different external dependencies from a single project with sbt-assembly

  5. 5

    How to include an external jar lib in my Ant build

  6. 6

    Using Maven in Ant for jar dependencies

  7. 7

    How to build an executable jar from multi module maven project?

  8. 8

    Maven and Netbeans: how do I build project and get executable jar?

  9. 9

    How can I create an executable JAR with dependencies using Maven?

  10. 10

    How to include http library in Android Project using M preview in Eclipse ant build

  11. 11

    External jar not importing in Eclipse Project

  12. 12

    External jar not importing in Eclipse Project

  13. 13

    java build ant file with external jar files

  14. 14

    How to generate Ant and Maven build files for an Eclipse Java project?

  15. 15

    How to build an executable jar in java

  16. 16

    Creating jar executable w/ external jar (JXL) in ECLIPSE java

  17. 17

    Adding external dependencies to ant project (IDEA Android project)

  18. 18

    Combine java code and dependencies into one jar (executable jar) using maven

  19. 19

    How to generate a jar with internal dependencies bundled and external dependencies as external jars?

  20. 20

    How do I refresh project dependencies using Buildship in Eclipse?

  21. 21

    How to provide Gradle dependencies for Ant build

  22. 22

    How do I create an executable jar file including dependencies where the main class is in Test, using Maven

  23. 23

    Spring Boot + Gradle: how to build executable jar

  24. 24

    Exclude Jar from Ant Build using zipgroupfileset

  25. 25

    Using cmake for a project with sub/external projects/dependencies

  26. 26

    How to build jar-file with ant?

  27. 27

    Eclipse ANT Build.xml create JAR is showing corrupted file

  28. 28

    Ant to Gradle: Executable JAR conversion

  29. 29

    How do I create an executable fat jar with Gradle with implementation dependencies

HotTag

Archive