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?

1
  • 1
    The explanations here may help you I think. Commented Jun 11, 2013 at 20:38

1 Answer 1

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

Would be the right way if you have your Controller class in the default package.

If you try to refer to your class as eclipse.bin.Controller the Java runtime will look for the Controller class within the package eclipse.bin and packages are not directories.

Sign up to request clarification or add additional context in comments.

2 Comments

Xerphiel, packages and the classpath are tricky to get to the bottom of, and you will have some frustration handling them. They are however required knowledge for a Java programer. They are kind of the linker configuration for Java if you know C/C++, although not that frustrating in my opinion.
Thanks for the info, I've looked at some tutorials but nothing is making huge amounts of sense (although it is late). Any good tutorials would be greatly appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.