-2

I compiled the Java project on Windows with java 1.8, it worked fine on my windows machine, then in my Ubuntu I set it up with Java 1.8 too, now Ubuntu says can’t find Main class, I researched the problem, didn’t help, I suspect it has something to do with the folder path, but i copied the entire project folder compiled by net-beans to my Ubuntu. my manifest file contents :

Manifest-Version: 1.0

X-COMMENT: Main-Class will be added automatically by build

aero
  • 372
  • 1
  • 4
  • 18
  • 2
    How are you trying to run the JAR file on both Windows and Linux? There ideally should be no depedencies on the OS (barring use of DLLs or something like that). – Tim Biegeleisen May 15 '16 at 05:37
  • it's still a JAR file, JAR actually run on both windows and Linux – aero May 15 '16 at 05:39
  • 1
    Wait...so it _does_ run or it doesn't? The error message sounds like a classpath problem. In other words, the JVM can't find the class which contains `main()`. – Tim Biegeleisen May 15 '16 at 05:41
  • no, it doesn't, what i'm saying is people are running JAR files on Linux all the time, i already copied the entire folder, so all .class files are there, as well as the manifest file. – aero May 15 '16 at 05:42
  • Show us the complete stacktrace. – Stephen C May 15 '16 at 05:43
  • Error: Could not find or load main class Main_Frame – aero May 15 '16 at 05:46
  • where Main_Frame is the main class file where the main method is – aero May 15 '16 at 05:46
  • Show us the **complete stacktrace**. (That is not a complete stacktrace.) Be sure to include any nested ("caused by") stacktraces. – Stephen C May 15 '16 at 06:12
  • that's all the screen shows, before i updated Java runtime i used to get errors about class loader, but after i updated to java 1.8, that's literally all i get, nothing else. – aero May 15 '16 at 06:22
  • The manifest has no meaning as a file on the file system. It only has meaning inside a .jar file. *Don't* copy your project. Build the .jar file on Windows. *Test* it on Windows (`java -jar xxx.jar`). Then copy the .jar file (nothing else) to Linux and run it there (same command). – Andreas May 15 '16 at 06:46
  • I guess @TimBiegeleisen couldn't get me an answer so he just decided to down vote my question instead, so did someone else. – aero May 15 '16 at 17:47
  • @aero I never downvoted you :-) – Tim Biegeleisen May 15 '16 at 22:43

1 Answers1

0

Your manifest file doesn't list the main class as well as the class path dependencies. So that means when you run the jar, you have to run by providing the class path as well as the main program to run.

For e.g.

java -cp /path/to/my/jar/dependencies -jar file.jar com.package.of.my.main.class.MyMainClass "any arguments if any"

Or have your manifest file provide both the class path and the main class and just run

java -jar file.jar

Vishal
  • 549
  • 3
  • 13