开发者

Failed to load Main-Class manifest attribute from

开发者 https://www.devze.com 2023-02-14 12:08 出处:网络
after export from eclipse i have error: C:\\Program Files\\Java\\jre6\\bin>java C:\\wamp\\www\\JOGL\\test.jar

after export from eclipse i have error:

C:\Program Files\Java\jre6\bin>java C:\wamp\www\JOGL\test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: C:\wamp\www\JOGL\test/jar
Caused by: java.lang.ClassNotFoundException: C:\wamp\www\JOGL\test.jar
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: C:\wamp\www\JOGL\test.jar.  Program will exit.

manifest from this file:

Manifest-Version: 1.0
Sealed: true
Main-Class: windows.SimpleScene

the same error when export with Fat Jar

updated:

C:\Program Files\Java\jre6\bin>java -jar C:\wamp\www\JOGL\test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/opengl/GLEventListener
        at java.lang.ClassLoader.defineClass1(Native Method)
   开发者_如何学Python     at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLEventListener
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 12 more
Could not find the main class: windows.SimpleScene. Program will exit.


To run a jar file, you run:

java -jar (name-of-jar-file)

So you should run:

java -jar C:\wamp\www\JOGL\test.jar


Make sure, when you are exporting and creating you JAR three things are set:

  1. Export it as a "runnable jar file".
  2. Define your launch configuration (which is your class that has the main method in it).
  3. select "Package Required libraries into generated JAR".

Failed to load Main-Class manifest attribute from


The command you entered only "java file.jar" is used to run .class files, the right syntax to run jar is the "java -jar file.jar" that search your jar for the manifest and execute it.

You can also run it by adding in the class-path and the main class name

java -cp C:\wamp\www\JOGL\test.jar com.ext.Example


That's not how you run a JAR file!

Use java -jar test.jar syntax


The reason you are seeing this error is java is looking at your current working directory as the classpath. where as your JAR file is located in a different directory.

You have the following options: 1) cd C:\wamp\www\JOGL java -jar test.jar (as you defined the Main-Class in the manifest file, java would pick it from there). Make sure your jar maintains the same directory structure as your package structure.

2) java -cp C:\wamp\www\JOGL\test.jar window.SimpleClass (pointing the classpath to your jar)

Note: If you have dependencies on other JARs/classes beyond this JAR file, they need to be part of the classpath (absolute/relative to current directory).

0

精彩评论

暂无评论...
验证码 换一张
取 消