0

I have an eclipse project which I want to run from the command line in ubuntu. After searching on the internet I am trying the following command.

java -cp . com.abc.utils.MyClassName

I issue this command from the directory that eclipse is using to store all the class files. But I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/abc/utils/MyClassName

what am I doing wrong and how to run the application from the command line ?

2
  • read this. It will help you... Commented Jul 12, 2012 at 9:40
  • Also when you have Eclipse, why you are running on command line? Commented Jul 12, 2012 at 9:40

3 Answers 3

1

Your command is right. You have missed something. Please check that

1. You have compiled your code and the MyClassName.class file is created in classes/com/abc/utils/ directory.

2. You are running this command from proper directory. Your current directory should be classes directory where your com directory is located. If it's not then switch to classes directory

$cd /path/to/project/folder/classes/

Hope that helps.

Additionally if you want to learn how eclipse automatically places .class and .java files then try compiling a multi-package application by yourself.

$javac -d would be helpful.

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

Comments

0

You can only run .class files aka compiled java files. So you first need to compile your java file with the 'javac' command. This will generate a .class file. Then you can run the java class file with the 'java' command.

3 Comments

but I have already compiled that code from eclipse and I am trying to run the compiled .class file that is inside the classes/com/abc/utils/ folder
try removing the -cp and without the . (dot)
Thanks dbf, its working now that I run this command from the classes directory.
0

you should set class path first

Comments

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.