0

I wrote and tested a small Java program using Eclipse. I'm now trying to deploy it on a Windows 7 box and Java cannot find the class. I copied the class file to C:\dxtester\classes. I'm trying to run it from the dxtester directory with: C:\dxtester>java -classpath classes;. dxtester

This produces this exception which I think I understand. Java examined the class file and is prompting me to provide the fully qualified name.

Exception in thread "main" java.lang.NoClassDefFoundError: dxtester (wrong name:
 dxtester/dxtester)

If I use the FQN I get

C:\dxtester>java -classpath classes;. dxtester.dxtester
Error: Could not find or load main class dxtester.dxtester

The application is a simple test driver where everything is done in main().

package dxtester;
public class dxtester {
    public static void main(String[] args) {

This seemed like an extremely simple thing to do but I'm completely baffled. What am I missing?

4

1 回答 1

1
  1. 您当前的目录是dxtester
  2. 在这个目录中你有dxtester.class(我想);
  3. 您的类路径是当前目录。

这个设置是错误的:你的类路径必须是基目录,这样包名就对应它的子目录。在您的情况下,您应该cd重复C:\该命令;但是,理想情况下,您的包结构将位于专用目录而不是根目录中。

我还应该提到类名应该在CamelCase.

于 2013-06-24T15:13:25.473 回答