1

I'm developing a Java-based app using Java8, JavaFX, and some other third-party libraries in IntelliJ. My project directory looks like this Project directory and main class file

Everything is working fine until the execution of JAR file. When I'm trying to run same using command java -jar myJarFile.jar it's giving this error "Could not find or load main class packageName.mainClassName". I checked the manifest file by unzipping the jar, that too is correct. Tried various solution available on StackOverflow and blogs but none worked. Please help, spent so much time on this.

Flown
  • 11,480
  • 3
  • 45
  • 62
  • What OS are you using? What is the output of running `java -version`? – Itai Feb 26 '18 at 19:20
  • packageName.mainClassName is probably coming from your MANIFEST.MF file. Change that to an actual entry point for your application. – Andrew Butenko Feb 27 '18 at 01:57
  • Make sure the correct main class name is written to manifest file. Make sure you have created the correct artifact in IDE: [usual jar artifact](https://www.jetbrains.com/help/idea/creating-running-and-packaging-your-first-java-application.html#package) or [JavaFX application jar](https://www.jetbrains.com/help/idea/packaging-javafx-applications.html) – Andrey Feb 27 '18 at 04:14
  • @sillyflyon I'm using windows 10 Pro. And on running java -version, I got: java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode) – Shubham Madheysia Feb 27 '18 at 04:18
  • @AndrewButenko by actual entry point, I guess you mean main class containing public static void main(String args[]) statement. Yes, its absolute path is set to main class file. Please see the manifest file screenshot here: https://i.imgur.com/vsqyn4S.png – Shubham Madheysia Feb 27 '18 at 04:22
  • what do you use as your build tool? ant/maven/gradle? depending on your setup MANIFEST.MF might be ignored altogether by your build tool. You would want to rename your freshly built jar into ".zip" and look inside META-INF/Manifest file. – Andrew Butenko Feb 27 '18 at 04:29
  • I'm using IntelliJ Build > Build Artifacts.. to build jar file As mentioned in question also, I had already extracted the jar file and seen the MANIFEST.MF file in /META-INF folder. It's exactly the same and path to Main-Class is also correct. – Shubham Madheysia Feb 27 '18 at 04:37

0 Answers0