Reputation: 3609
I have a Java project,Parent
, which depends on a Child
sub-project (in the form of a JAR). This Child
depends on library A
and B
and those get bundled in with Child
. Parent
uses A
and B
as well (meaning direct calls, not indirect through Child
. I want to be able to include A
and B
JARs only once in my project.
When I am compiling Parent
, I get a cannot find symbol
when it references libraries A
and B
. I believe this is because Child
is on the compile time path, but for some reason the libraries within it are not.
I am using ant as my building tool - is there anything special I should be doing in my javac tags for nested jars? Right now in Parent
's build.xml I have:
<target name="compile" depends="clean, makedir">
<javac
srcdir="${src.dir}"
destdir="${build.dir}"
includeantruntime="false"
classpathref="build.classpath">
</javac>
</target>
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
This should be including all of the jars present in my lib folder, but it doesn't seem to include all of the jars within jars.
Upvotes: 0
Views: 803
Reputation: 3609
My problem stemmed from the fact that Java cannot natively reference jars inside of jars. You'll need to use something like http://one-jar.sourceforge.net/ to get around it.
Upvotes: 0
Reputation: 16235
I assume that A.jar
and B.jar
are thirdparty libraries, rather than outputs of your own build.
In that case, one way to resolve this would be to create a project or directory for thirdparty libraries which can then be used by your multiple projects. In the environment you have described, your Child
project will bundle them into its own build output and the Parent
project will use them directly on its classpath.
Lets say that your create your thirdparty
project at the same level in the file system as your other projects:
thirdparty
lib
A.jar
B.jar
Parent
build.xml
src
Child
build.xml
src
In your build files, you can define the location of the thirdparty project:
<property name="thirdparty" value="../thirdparty"/>
and reference it in paths:
<include name="${thirdparty}/lib/A.jar"/>
<include name="${thirdparty}/lib/B.jar"/>
Upvotes: 1