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?
-
Did you try setting the working directory to "build\classes" in the Project Properties -> Run tab?
-
At least one of the JARs/Libs referenced by your project may not be being copied to the class path of your program. Copy all of the jars/libs that your project uses to the /dist folder of your project (or wherever YourApplication.jar is), then try to run your program. If this fixes it it means your Netbeans project isn't configured quite correctly.
-
The error you're getting means that one of the following is true:
- The class
IndexBuildercannot be found on the classpath - A necessary (for class loading) dependency of
IndexBuildercannot be found on the classpath
That is, when loading the class, it's possible (even likely) that the class can be found but that some critical dependency of the class cannot be found. For example, if
IndexBuilderextends another class and that base class cannot be found on the classpath, you'll get this error. Another example is ifIndexBuilderuses a class in a static initializer and that class cannot be found.Check your classpath not just for
IndexBuilderbut also for anything thatIndexBuilderdepends on.See, for example, this discussion of
NoClassDefFoundError. - The class
-
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:
<property file="myproject.properties"/>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.
-
Are you running this on Windows or Unix. If Windows, try changing your property file to:
run.classpath=${javac.classpath};${build.classes.dir}Please note the semicolon instead of a colon.
Hank Gay : This is on Mac OSX, so Unix.Bogdan : Can you post a snippet from your Ant build file?
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.