NoClassDefFoundError on command line with new NetBeans project
I created a new J2SE project in NetBeans and I can run it from the IDE, but when I try to run it with Ant in the command line, I get the following problem:
<incision>
run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: IndexBuilder
[java] Java Result: 1
<incision>
Based on the snippet project.properties
below, the class should be found.
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
How do I fix this?
source to share
When you run it from the command line, you are actually invoking Apache Ant . The reason you get a ClassNotFound exception is because $ {javac.classpath} and all other properties are not filled in correctly. This is why your code runs out of the Netbeans context. Netbeans sets these properties for you.
To answer your original question about how you are going to run it from the command line, you either need to configure a properties file that defines these parameters with a property declaration:
<property file="myproject.properties"/>
Another solution is to set properties as environment variables via sh script. Or you can use real paths in build script instead of properties.
For details on how to invoke Ant from the command line, see here .
source to share
The error you are receiving means that one of the following conditions is true:
- The class
IndexBuilder
could not be found on the classpath - Required (for class loading) dependency
IndexBuilder
could not be found on the classpath
That is, when loading a class, it is possible (even likely) that the class can , but cannot be found, any critical class dependency. For example, if you IndexBuilder
extend another class and that base class cannot be found in the classpath, you will get this error. Another example: if IndexBuilder
uses a class in a static initializer and this class cannot be found.
Check the classpath not only for IndexBuilder
but for everything that depends on IndexBuilder
.
See, for example, this discussion NoClassDefFoundError
.
source to share
At least one of the JARs / Libs referenced by your project may not be copied to the classpath of your program. Copy all the jars / libraries your project uses to your project's / dist folder (or wherever you are, YourApplication.jar) and then try running your program. If this is fixed, it means that your Netbeans project is not configured correctly.
source to share