1

I exported an executable Jar file from Eclipse. On Windows when I double-click the file, it executes properly. When I run it from command line with java -jar MyJar.jar it also works. But when I upload that file on my linux VPS and try to run it there, I just get the error

Error: Could not find or load main class mypackage.MyClass

I tried many things like changing CLASSPATH, trying out different Class-Paths and Main-Classes in the MANIFEST.MF file, and even trying to execute the program from .class files without the jar container. But unfortunately nothing works.

Do you have any ideas? Or did you face the same problem?

EDIT:
Manifest:

Manifest-Version: 1.0
Class-Path: .
Main-Class: mypackage.MyClass

Name: about.html
SHA-256-Digest: 1fuYr0bu6NsJZCAmSom5QtnvnV0Cg8DwLn77Dd1Ql24=

Name: jfx8.cssext
SHA-256-Digest: b2p9PXeoxqnTdYgBFeKp3s7J9PajukOS3sGqyM4s36I=
jomority
  • 39
  • 5
  • On your VPS, is `java -version` showing the correct version? – Tassos Bassoukos Jan 10 '16 at 21:02
  • paste the Manifest. But most probably classpath issues, and the command you are using – Antoniossss Jan 10 '16 at 21:05
  • See http://stackoverflow.com/questions/13030675/could-not-find-or-load-main-class-with-a-jar-file – ROMANIA_engineer Jan 10 '16 at 21:07
  • On my VPS and on my Windows Pc the Java Version is `1.8.0_66`. – jomority Jan 10 '16 at 21:15
  • an the jar contains directory structure of `mypackage\MyClass.class` ?? – Antoniossss Jan 10 '16 at 21:20
  • Have you tried `java -jar `? – Ortwin Angermeier Jan 10 '16 at 21:21
  • @Antoniossss Yes, ic checked that several times. The strange thing is, when i create a testclass like in the link from engineer, everything works fine. But when I use the Eclipse classes I get this error. Ortwin Angermeier Yes, I tried that too – jomority Jan 10 '16 at 21:29
  • Could it have something to do that the main Class is a JavaFX Application? I dont think so, because it contains a main method an that is what the java runtime is looking for, isnt it? – jomority Jan 10 '16 at 21:35
  • What do you mean "eclipse classes" ?? Is there a difference between what u are doing and in mentioned link? – Antoniossss Jan 10 '16 at 21:43
  • @Antoniossss I mean that if I do this little Hello world programm it works fine. But when I copy the .class file from the Eclipse project folder to the VPS and try to run it, I get the same Error. – jomority Jan 10 '16 at 21:50
  • Well, now I made a new Project in Eclipse without a package. Now all the class files are in the root of the jar file. But linux java still says it cannot find or load the Main class. – jomority Jan 10 '16 at 21:58
  • Maybe you have classname mismatch (a typo). Remember it has to be case sensitive. Anyway, it is hard to tell anything else based on your "description" without seeing directory structure, classes, run command etc. If JVM says that class is not there then it is not there. Simple. – Antoniossss Jan 10 '16 at 23:31

1 Answers1

1

I finally solved my problem!!

The problem was that no JavaFx runtime was installed on the VPS. Don't know why that caused that error. I rewrote the Application without JavaFx and now it works.

Thank you for all your help.

jomority
  • 39
  • 5