如何抛出NoClassDefFoundError [英] How is NoClassDefFoundError thrown
问题描述
F:\workspace\helloWorld\src\com\hello;
HelloWorld.class已放入
F:\workspace\helloWorld\bin\com\hello。
它在Eclipse中工作得很好。但是当我进入目录 F:\workspace\helloWorld\bin\com\\hello
并使用命令行java HelloWorld时,我得到 NoClassDefFoundError的
。我知道它可能与类路径有关。但是我不太确定。
你的课程是在一个包 com.hello
。要运行它,您必须确保您的包中的基本目录是
F:\workspace\helloWorld\bin
案例,在类路径。
尝试运行如下:
java -cp F:\workspace\helloWorld\bin com.hello.HelloWorld
您也可以转到 F:\workspace\helloWorld\bin
目录,然后使用
java com.hello.HelloWorld
这将工作,因为Java将使用当前目录作为默认(如果您没有设置 CLASSPATH
环境变量)。
I built a package called "com.hello" in eclipse and I wrote an easy HelloWorld program. Eclipse automatically added "package com.hello;" on top of my program. And HelloWorld.java was put in
F:\workspace\helloWorld\src\com\hello;
HelloWorld.class was put in
F:\workspace\helloWorld\bin\com\hello.
It worked very well in Eclipse. But when I entered the directory "F:\workspace\helloWorld\bin\com\hello
" and used command line with "java HelloWorld," I got NoClassDefFoundError
. I know it may have something to do with the classpath. But I'm not quite sure.
Your class is in a package com.hello
. To run it, you must make sure the base directory of the package, which is F:\workspace\helloWorld\bin
in your case, is in the classpath.
Try running it like this:
java -cp F:\workspace\helloWorld\bin com.hello.HelloWorld
You can also go to the directory F:\workspace\helloWorld\bin
and then run it with
java com.hello.HelloWorld
This will work because Java will use the current directory as the default (if you do not have the CLASSPATH
environment variable set).
这篇关于如何抛出NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!