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.
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.
Comments