It is my first time I'm writing here, so I'm hoping that I'm making everything right.
I have a Java application, let's call it A. This application depends on another project B (required project on the build path). The project structure looks as follows:
CommonFolder/Project B
-- src
-- lib
build.xml
CommonFolder/subfolder/Project A
-- src
-- lib
-- config
build.xml
The build.xml in Project B works well and create a jar file in a dist folder. Now in Project A the build.xml file should first call build.xml from Project B and then it should create the jar file. Somehow this does not work. If I just copy the jar file from Project B into the lib folder of Project A it works but I don't want to do this manually.
My second problem is that the final jar file of project A will be pretty big because there are a lot of libraries in the lib folder. I would like to split the jar file into two files: libraries.jar (also containing the dependency from project B) and application.jar. When application.jar is started it should use libraries.jar (both jars in the same folder). The benefit is that I only have to upload application.jar which is much smaller (if I don't change the libraries).
How can this be done?
I'm looking forward for the answer.
Here are both build.xml files.
ProjectB
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="complete build" name="Create runnable jar file">
<property name="src.dir" location="src" />
<property name="lib.dir" location="lib" />
<property name="build.dir" location="bin" />
<property name="dist.dir" location="dist" />
<property name="build.sysclasspath" value="last" />
<path id="project-classpath">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<target name="remove release">
<delete dir="${dist.dir}" />
</target>
<target name="clean build">
<delete dir="${build.dir}" />
</target>
<target name="compile" depends="clean build">
<mkdir dir="${build.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on" target="1.8" source="1.8">
<classpath refid="project-classpath" />
<compilerarg value="-Xlint:none" />
</javac>
</target>
<target name="build jar" depends="remove release, compile">
<mkdir dir="${dist.dir}" />
<jar destfile="${dist.dir}/projectA.jar">
<fileset dir="${build.dir}" />
<zipgroupfileset dir="lib" excludes="META-INF/**" includes="*.jar"/>
</jar>
<antcall target="clean build" />
</target>
<target name="complete build" depends="build jar, clean build" />
</project>
Project A
<path id="project-classpath">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<target name="remove release">
<delete dir="${dist.dir}" />
</target>
<target name="clean build">
<delete dir="${build.dir}" />
</target>
<target name="clean docs">
<delete dir="${docs.dir}" />
</target>
<target name="build-deps">
<ant antfile="../../ProjectB/build.xml" target="complete build"/>
</target>
<target name="compile" depends="clean build, build-deps">
<mkdir dir="${build.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on" target="1.8" source="1.8">
<classpath refid="project-classpath" />
<compilerarg value="-Xlint:none" />
</javac>
</target>
<target name="docs" depends="clean docs, compile">
<mkdir dir="${docs.dir}" />
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<target name="build jar" depends="remove release, compile">
<mkdir dir="${dist.dir}" />
<jar destfile="${dist.dir}/ProjectA.jar">
<manifest>
<attribute name="Main-Class" value="something.main.Main" />
<attribute name="Class-Path" value="." />
</manifest>
<fileset dir="${build.dir}" />
<zipfileset dir="config" />
<zipgroupfileset dir="lib" excludes="META-INF/**" includes="*.jar"/>
</jar>
<antcall target="clean build" />
</target>
<target name="complete build" depends="docs, build jar, clean build" />