简体   繁体   中英

Why am I getting a ClassNotFoundException in a java application?

I am getting an error that states, java.lang.NoClassDefFoundError: usemathobject/Main and I'm not sure why I'm getting it.

After doing some searches, I found a thread that deals with this error. In that thread, it says I need to modify the MANIFEST.MF file, but it doesn't explain clearly to me how to modify that file. It specifies what to put on the command line but not what to put in the MANIFEST.MF file. I also tried adding

Main-Class: "C:\Users\MyName\Documents\NetBeansProjects\UseMathObject\src\usemathobject\UseMathObject.java"

to Manifest.mb , as suggested on https://blogs.oracle.com/olaf/entry/jdev_including_a_classpath_in but that didn't work.

I am using NetBeans IDE 6.9.1 on Windows Vista .

Main-Class: usemathobject.UseMathObject

您给包和类名,而不是文件路径。

Here is the way to set entry point for stand-alone applications bundled into executable jar file. The use of the below option creates or overrides the Main-Class attribute value in the manifest file. This option can be used during creation of jar file or while updating the jar file. This option specifies the application entry point without editing or creating the manifest file.

For example, this command creates Main.jar where the Main-Class attribute value in the manifest is set to Main:

jar cfe Main.jar Main Main.class

The java runtime can directly invoke this application by running the following command:

java -jar Main.jar

I think that the problem here is that you do not understand what you are doing, you are randomly trying things that people are telling you ... without understanding what they are saying means. And you are not understanding what the error messages are telling you.

I think you would be better off trying to understand how Java's package, classpath and jar file mechanisms work. Read the following sections of the Oracle Tutorials:

Once you've read and understood these sections, it will all make sense ... and you will be able to figure out what you are doing wrong and how to fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM