0

I've been writing simple programs in Java, but seem to run into problems where the class path is involved.

My compiled class files exists in the directory: /home/pi/code/java/eclipse/bin/

When in this directory I can run "java Controller" and the program will run.

Experimenting with the class path I tried the following:"java -cp /home/pi/code/java/ eclipse.bin.Controller"

But I get the following exception:

"Exception in thread "main" java.lang.NoClassDefFoundError: eclipse/bin/Controller (wrong name: Controller)
"

The weirdest thing is that Java even constructed the final section "eclipse.bin.Controller", e.g. I could tab it when i was typing the command, so I expected this to work.

My end goal is to point the class path at a JDBC driver.

Where am I going wrong?

4

1 に答える 1

1
java -cp /home/pi/code/java/eclipse/bin Controller

Controllerクラスがデフォルトのパッケージに含まれている場合は、これが正しい方法です。

eclipse.bin.ControllerJava ランタイムとしてクラスを参照しようとするとController、パッケージ内のクラスが検索されeclipse.binますが、パッケージはディレクトリではありません。

于 2013-06-11T20:31:21.357 に答える