0

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.

Anthony Neace
26.2k8 gold badges118 silver badges132 bronze badges
asked Oct 16, 2012 at 7:41

2 Answers 2

4

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).

answered Oct 16, 2012 at 7:44
Sign up to request clarification or add additional context in comments.

1 Comment

That really works! Thank you very much! I've been learning RMI with command line. And this problem is puzzling me! Thx again~
0

Go to F:\workspace\helloWorld\bin\ and run it this way:

java -cp .; com.hello.HelloWorld
answered Oct 16, 2012 at 7:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.