0

I have java 8 installed on fedora 20. Any java program runs perfectly fine via eclipse but when I run the same program on terminal it reports an error saying 'could not load main class' . what could be the problem?

I wrote a simple helloworld program named hello.java and executed on eclipse. Then I opened terminal and moved to the folder containing the hello.class in eclipse workspace and typed ' java hello '. But it said 'error:could not load main class'.

Also as I said I have installed and I use oracle java 8.

  • Welcome to Unix.SE! You need to give a little more detail: what command are you typing to start your program? Please edit your question to add the info. – Stephen Kitt Jun 29 '15 at 7:57
  • Could you please paste the code of your Hello.java file? – binfalse Jun 29 '15 at 8:32
0

You need to open it with java -jar Hello

  • It did not work. – Aditya Gupta Jul 3 '15 at 17:43
  • What's the error? – nifker Jul 3 '15 at 17:44
  • Error: unable to access jarfile Hello – Aditya Gupta Jul 4 '15 at 15:29
  • Have you given the file execute permission? – nifker Jul 10 '15 at 0:03
0

in terminal type java -version and observe the version that appear.

say, it is v1

in eclipse Window->Preferences->Java compiler, check version

say it is v2

To work v2 must be <= v1, if eclipse has newer java version you need one of two:

1) install newer java on linux 2) downgrade java compiler in eclipse

  • Java version at both the places is 1.8 . – Aditya Gupta Jul 4 '15 at 15:27
  • Check that: stackoverflow.com/questions/18093928/… – Vladimir Nabokov Jul 4 '15 at 17:24
  • Yeah.... Found the solution. I had to use '-cp . ' option to include the current directory in class path. Surprisingly it java does not even look in the current working directory for .class files. I had to use ' java -cp . Hello' to run the class file. – Aditya Gupta Jul 26 '15 at 11:14

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.