I am a beginner to Java as well as to Ubuntu.

I downloaded JDK 10.0.2 zip file and unzipped using tar command.

I used vim .bashrc and typed the following

export JAVA_HOME=path of my Java
export PATH=$JAVA_HOME/bin:$PATH
source .bashrc

echo $JAVA_HOME and echo $PATH giving the correct path of my Java 10.0.2

I am able to compile the file using the javac command and .class file created successfully.

When I am running java ( java ./Desktop/app/Numbers) referring to the class file, I am not able to run and getting the "Main class not found exception"

But, when I go to that particular folder and execute the javac as well as java, I am getting the output.

What I have tried

1) vim .bashrc and typed the above. But it didn't work.

2) sudo vim ./etc/environment and tried adding within the quotes :/javapath/bin". It didn't work.

Guide me where I am going wrong.

  • Use ~/Desktop/app/Numbers instead! You seem to have a dot before that path Aug 22, 2018 at 14:04
  • I tried java ~/Desktop/app/Numbers and still getting the same error.
    – hawk base
    Aug 22, 2018 at 14:10

1 Answer 1


Ok run that command like this:

java -classpath /home/$USER/Desktop/app Numbers

Since your running it from another location java expects this format:

java -classpath /path/to/class/file class_file_name

NOTE: The space between path and class file name. See java -help or man java

  • Thanks. It worked. I typed java -cp (classpath too working) ./Desktop/app Numbers. Do I need to run this every time when I run the program ? Is this the same for running jar file as well ?
    – hawk base
    Aug 22, 2018 at 14:22
  • Yes I believe so -cp <class search path of directories and zip/jar files> run java -help to see more and please kindly accept my answer by clicking on the check mark beside it. Aug 22, 2018 at 14:25
  • Being a new user, I am not able to check the mark as it's asking to wait for 15 mins.
    – hawk base
    Aug 22, 2018 at 14:28
  • That's fine return to do that then, cheers! Aug 22, 2018 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.