I’ve created a new J2SE project in NetBeans, and I can run it from the IDE, but when I try to run it using Ant on the command line, I get the following problem:
<snip>
run: [java] Exception in thread 'main' java.lang.NoClassDefFoundError: IndexBuilder [java] Java Result: 1
<snip>
Based on the snippet from project.properties below, the class should be found.
run.classpath=\ ${javac.classpath}:\ ${build.classes.dir}
How do I go about fixing this?
When you are running it from the command line, you are actually invoking Apache Ant. The reason you are getting the ClassNotFound Exception is because ${javac.classpath} and all the other properties are not being properly populated. That is why your code runs from within the Netbeans context. Netbeans is setting those properties for you.
To answer your original question of how do you go about getting it to run from the command line, you need to either set up a properties file that defines those parameters via a property declaration:
Another solution is to set the properties as environment variables via a sh script. Or you can use real paths in the build script instead of properties.
See here for more details on how to invoke Ant from the command line.