0

I have created a Java program:

public class Hello{
public static void main(String[] args) {
    System.out.println("HEllo world");
}
}

My /etc/environment file looks like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/$JAVA_HOME="/usr/lib/java/jdk1.8.0_131/bin/java" " 

My java program gets compiled perfectly.

nehal@nehal-Inspiron-5559:~/Desktop$ javac Hello.java 
nehal@nehal-Inspiron-5559:~/Desktop$ java Hello
Error: Could not find or load main class Hello

When I run it it gives me this error.
The path where my java is installed:

/usr/lib/java/jdk1.8.0_131/bin

How can resolve this issue?
P.S. Initially i had open-jdk installed,but i removed it completely and installed Oracle Java8

Edit:
The above problem is still unsolved but my code runs when I run it like:

java -cp . Hello
  • Just to test, can you do: cd ~/Documents && gedit Hello.java then, copy your code to this file, then javac Hello.java && java Hello – Raphael Jul 15 '17 at 6:11
  • @Raphael Same error – nrb Jul 15 '17 at 6:39
  • 1
    Please post the output of echo $JAVA_PATH – George Udosen Jul 15 '17 at 7:33
  • @George nehal@nehal-Inspiron-5559:~$ echo $JAVA_HOME /usr/lib/jvm/java-8-oracle – nrb Jul 15 '17 at 7:39
  • What of echo $PATH | grep -i java? – George Udosen Jul 15 '17 at 7:42
0

Please change:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/$JAVA_HOME="/usr/lib/java/jdk1.8.0_131/bin/java" " 

To:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" 

JAVA_HOME="/usr/lib/java/jdk1.8.0_131" 

Then source the /etc/environment with source /etc/enviroment.

Now run echo $JAVA_PATH

  • My /etc/environment was previously: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVA_HOME="/usr/lib/java/jdk1.8.0_131" I changed it to the new path – nrb Jul 15 '17 at 7:44
  • What does this mean? ->Then source the /etc/environment with source /etc/enviroment – nrb Jul 15 '17 at 7:47
  • It simply means to reload that file so your environmental settings can be picked up after the changes – George Udosen Jul 15 '17 at 8:26
  • You missed an n in the spelling of environment – George Udosen Jul 15 '17 at 8:29
  • can you create a chat room? – nrb Jul 15 '17 at 8: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.