无法找到主类

时间:2013-06-29 18:55:34

标签: java jar

我正在尝试使用cmd运行名为easyflow-gui.jar的jar中捆绑的java程序:

java -classpath "." -jar easyflow-gui.jar

工作目录是包含所有相关库的目录。

我尝试运行的jar文件的Manifest文件的内容是:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_32-b27 (Sun Microsystems Inc.)
Main-Class: easyflow.custom.jgraphx.editor.SchemaEditor

此尝试的结果是:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mxgraph/util/mxEventSource$mxIEventListener
Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: easyflow.custom.jgraphx.editor.SchemaEditor. Program will exit.

问题:实际上找不到哪一个类:mxEventSource $ mxIEventListener或主类easyflow.custom.jgraphx.editor.SchemaEditor?

编辑1: 我检查了文件夹并提取了罐子,我发现这两个类都可用(捆绑到工作目录中的各自的罐子里):

$ls easyflow/custom/jgraphx/editor/SchemaEditor*
easyflow/custom/jgraphx/editor/SchemaEditor$1.class
easyflow/custom/jgraphx/editor/SchemaEditor$2.class
easyflow/custom/jgraphx/editor/SchemaEditor.class
easyflow/custom/jgraphx/editor/SchemaEditor.java
$ls com/mxgraph/util/mxEventSource*
com/mxgraph/util/mxEventSource$mxIEventListener.class
com/mxgraph/util/mxEventSource.class

3 个答案:

答案 0 :(得分:1)

如果要包含jar文件,则不能为类路径指定".",它必须是以冒号分隔的jar文件或目录列表(或以分号分隔,具体取决于操作系统)。尝试使用java -help来获取命令行选项的说明。

另外,如果我没记错-jar-classpath不能一起使用,那么您必须单独使用-classpath并明确指定主类。

尝试类似

的内容
java -cp easyflow-gui.jar:foo.jar:bar.jar easyflow.custom.jgraphx.editor.SchemaEditor

...其中foo.jarbar.jar是“其他相关库”。

答案 1 :(得分:0)

如果您正确阅读了例外,您将看到错误原因:

Caused by: java.lang.ClassNotFoundException: com.mxgraph.util.mxEventSource$mxIEventListener

您没有在类路径中包含包含com.mxgraph.util.mxEventSource$mxIEventListener的jar文件。通过快速谷歌搜索,您将需要jGraph库。

我希望这会有所帮助。

答案 2 :(得分:0)

默认的类路径是当前的工作目录。 因此,如果您已在当前工作目录中拥有jar,则无需明确指定类路径。

以下命令应该起作用

java -jar easyflow-gui.jar
相关问题