0

I'm trying to create an Exe file for my JavaFX project, after building the artifacts I try to run the jar by java -jar name.jar and I get the error at the title.

I was following the answer here What does "Could not find or load main class" mean? but nothing helped.

Then i tried to do this method https://www.youtube.com/watch?v=HuFOCEHh8Zg&feature=youtu.be and it still happened.

In the project i use mssql-jdbc-8.4.1.jre14.jar , mysql-connector-java-5.1.49.jar , jfoenix-9.0.10.jar and of course the JavaFx lib.

The values of CLASSPATH in the system variable are : CLASSPATH

The libs at the project: libs

MANIFEST:

Manifest-Version: 1.0
Main-Class: MainPackage.Main
Class-Path: C:\Users\amttr\Desktop\pol\javafx-sdk-11.0.2\lib\* C:\Users\amttr\Desktop\pol\lib\*

Any suggestions?

Afik.M
  • 13
  • 1
  • 3
  • If you are using the `-jar` option, then the setting of CLASSPATH is irrelevant. The only thing that affects the classpath for an executable JAR is the setting in the JAR file manifest. See https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html. – Stephen C Nov 12 '20 at 13:28
  • 1
    (P.S. I'm not watch a video. For a start, it doesn't tell us what you *actually* did. Likewise, telling us that you "followed" some other Q&A doesn't tell you what you actually did either.) – Stephen C Nov 12 '20 at 13:31
  • Thanks for the quick answer. I read the doc 3 times and still couldn't understand what should be the value of class-path at manifest depending on my libs. @StephenC – Afik.M Nov 12 '20 at 13:57
  • You will need to list in the jar manifest class-path the relative path to the library jars you've used. Depending on the version of JRE you are using, you may need to make adjustments so the JavaFX modules are visible as well. You also haven't provided the full output from attempting to run your program. – swpalmer Nov 12 '20 at 17:06
  • Does name.jar have a `META-INF/MANIFEST.MF` entry in it? Does that entry’s content contain a `Main-Class` line? – VGR Nov 12 '20 at 18:03
  • @VGR Yes there is a `Main-Class` line with the correct class. And `Class-Path: C:\Users\amttr\Desktop\pol\javafx-sdk-11.0.2\lib\* C:\Users\amttr\Desktop\pol\lib\*` – Afik.M Nov 12 '20 at 18:23
  • @swpalmer What kind of adjustments i have to do ? and the full output: `Error: Could not find or load main class MainPackage.Main Caused by: java.lang.ClassNotFoundException: MainPackage.Main` – Afik.M Nov 12 '20 at 18:34
  • Your Class-Path is invalid. The entries in a manifest Class-Path are not identical to the entries that would be allowed in a `-cp` argument. They must be relative URLs, which means they must not start with `C:` and they must use forward slashes (`/`) to separate directory names. And they must point to actual .jar files; the convenience of ending with `*` is not permitted here. See [the Class-Path section of the jar specification](https://docs.oracle.com/en/java/javase/15/docs/specs/jar/jar.html#class-path-attribute). – VGR Nov 12 '20 at 18:41
  • @VGR So you mean that I have to add every jar that I used separately include the JavaFx jars? Do you have any sample for correct MANIFEST? – Afik.M Nov 12 '20 at 18:46
  • Yes. That jar specification link has some examples. Another option is [creating a deployable application image](https://stackoverflow.com/questions/53453212/how-to-deploy-a-javafx-11-desktop-application-with-a-jre/53453519#53453519), if you’re using Java 9 or later. – VGR Nov 12 '20 at 18:58
  • @VGR Hi, after some tests i found out that the `mssql` jar makes the trouble (While the Class-Path is empty). Any idea for including this jar as well without getting an error? – Afik.M Nov 17 '20 at 14:06

0 Answers0