2

I'm extending my company's ant build script to add in a special module we want build in some cases. I've written an ant script that points to where I know the compiled class files for the rest of our codebase are, because they get compiled earlier in the build process. I know with 100% certainty the files are in this location.

However, whenever I try to compile this module, the classpath reference can't see those classes, and I get a bunch of "package does not exist" and "can't find symbol" errors. What am I doing wrong?

Here's my build script code:

<property name="classpath" value="${dir.dev}/out/production/Main" <path id="pfClasspath"> <fileset dir="${classpath}"> <include name="**/*.class"/> </fileset> <fileset dir="${dir.dev.lib}"> <include name="**/*.jar" /> </fileset> <fileset file="${lib.json}" /> <!-- TODO try removing this --> </path> <target name="compile" depends="prepare"> <javac source="1.7" classpathref="pfClasspath" srcdir="${dir.project}/src" destdir="${dir.project.build.classes}" /> </target> 

The directory the "classpath" property is pointing at 100% contains all of the class files for the rest of the project. That level is the equivalent of the "src" directory on the sources side, immediately within it are the com/companyName/etc... folders.

My code contains references to the classes compiled at this location. Yet ant isn't finding them.

3
  • what does prepare do? Commented Jul 13, 2016 at 20:36
  • You didn't close your property tag. Commented Jul 13, 2016 at 20:41
  • That was probably a bug when I copied it over, that tag is closed in the original file. Good catch though. Commented Jul 14, 2016 at 12:50

1 Answer 1

1

Try

<path id="pfClasspath"> <pathelement path="${classpath}" /> ... </path> 

instead. Specifying the classpath does not mean to specify every single class file that's on the classpath, which is what you do when you define your <path> element using a <fileset>.

Sign up to request clarification or add additional context in comments.

2 Comments

So the directory pfClasspath is pointing at has a LOT of classes in it. It's a giant directory hierarchy with probably several hundred .class files. Will pathelement still work then?
@user2223059: Yes, I'm pretty sure it will work. What will happen under the hood is that the compile target will invoke javac like this: javac -cp ${dir.dev}/out/production/Main;${dir.dev.lib}/MyJar1.jar;${dir.dev.lib}/MyJar2.j‌​ar -sourcepath .... Whenever javac finds a symbol like, say, myapp.MyClass, it will first search for a file myapp/MyClass.class relative to ${dir.dev}/out/production/Main, then inside ${dir.dev.lib}/MyJar1.jarand finally inside ${dir.dev.lib}/MyJar2.jar. No matter how many files are actually inside the directory ${dir.dev}/out/production/Main.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.