0

我在 eclipse 中创建了一个程序,已将其导出到 JAR,但是当我尝试运行它时,出现以下错误:

Error: Could not find or load main class

我不明白为什么它找不到它,因为我已经说明了主要课程在哪里。我的清单文件如下所示:

Manifest-Version: 1.0
Main-Class: gui.GeoMapItMain
Class-Path: mysql-connector-java-5.1.25-bin.jar
Class-Path: JMapViewer.jar
Class-Path: colt.jar
Class-Path: metadata-extractor-2.6.4.jar
Class-Path: JMapViewer_src.jar
SplashScreen-Image: images/splash.gif

我在带有以下版本 JDK 的带有 Mountain Lion 的 Mac 上使用 java:

javac 1.7.0_13
java version "1.7.0_13"

我现在已经尝试过了:

java -jar GeoMapItJ.jar

这给了我一个错误如下:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openstreetmap/gui/jmapviewer/interfaces/MapMarker
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
    at java.lang.Class.getMethod0(Class.java:2694)
    at java.lang.Class.getMethod(Class.java:1622)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.openstreetmap.gui.jmapviewer.interfaces.MapMarker
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 6 more
4

1 回答 1

1

问题是清单中的 for 语法Class-Path要求条目以空格分隔,而不是在单独的行上。请参阅JAR 文件规范

拥有多个Class-Path键是错误的。jar如果您将详细标志传递给该工具,该工具将警告您:

$ jar cvfm foo.jar manifest Foo.class 
Jun 12, 2013 9:53:19 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path.
Ensure that the manifest does not have duplicate entries, and
that blank lines separate individual sections in both your
manifest and in the META-INF/MANIFEST.MF entry in the jar file.
Jun 12, 2013 9:53:19 PM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path.
Ensure that the manifest does not have duplicate entries, and
that blank lines separate individual sections in both your
manifest and in the META-INF/MANIFEST.MF entry in the jar file.
Jun 12, 2013 9:53:19 PM java.util.jar.Attributes read
...

额外的Class-Path条目被忽略,这会导致异常

java.lang.ClassNotFoundException: org.openstreetmap.gui.jmapviewer.interfaces.MapMarker

因为在Class-Path处理的条目中没有指定类。

于 2013-06-13T03:56:40.670 回答