0

I know this error has been solved by other people for Maven and Gradle and SpringBoot, but I'm having an issue running a jar file after using Netbeans.

java -jar FantasyFX.jar

Unfortunately, it responds with

"no main manifest attribute, in FantasyFX.jar"

I am using Netbeans 12.6, with JDK 17.0.2, ANT version 1.10.8, JavaFX 18.0.1, and JRE 1.8.0_333

I am following the instructions exactly from https://openjfx.io/openjfx-docs/ Specifically section Netbeans->Modular From IDE Where I select 'Java Modular Project' just as their instructions show. I also heeded their warning:

Warning: Don't try to create a JavaFX project. The JavaFX Ant tasks of the current Apache NetBeans version are not ready for JavaFX 11+ yet, unless you have a custom JDK that bundles JavaFX, as described in Custom JDK+JavaFX image.

And so I made sure not to create a JavaFX project, just a Java with Modular again like they recommended.

After several hours of research and tinkering, I found the closest solution to it was to add this to my build.xml file, as it overrides the jar code found in build-inst.xml (which I know I'm not supposed to edit directly so I did not):

<target depends="-pre-single-jar" if="module.jar.filename" name="-make-single-jar">
    <jar basedir="${module.dir}" compress="${jar.compress}" destfile="${dist.dir}/${module.jar.filename}" excludes="${dist.archive.excludes}" manifestencoding="UTF-8">
        <manifest>
            <attribute name="Main-Class" value="mainpackage.Main" />
        </manifest>
    </jar>
</target>

That generated everything (seemingly) normally, but then it gives me a new error, telling me it could not find a main class in mainpackage.Main, with a noclassdeffounderror for javafx/application/Application.

I double-checked everything in the files, including the mainpackage's Main, and made sure there's no typos.

So it kinda brought be back to square one, unfortunately.

I did find a conjecture on an answer for that at https://stackoverflow.com/a/18344096/16831808 Where they stated that

I've worked on this very same issue for the past few hours. Even though I haven't seen it written explicitly, it appears that you MUST use one of the JavaFX packaging tools, which is either an Ant task or the javafxpackager executable.

Is that true? Do I need to package before I can execute the jar file it generates in the dist folder?

PS. double-clicking on said jar file does nothing either

  • Is `JRE 1.8.0_333` correct? – SedJ601 Jun 19 '22 at 02:14
  • Yes, that is the version name – Patrick Abbey Jun 19 '22 at 03:15
  • 1
    JavaFX 11+ *requires* JDK 11+, it is not going to work with JDK 8. I advise using the latest stable versions of all software (jdk, JavaFX, ide, build tools, etc). – jewelsea Jun 19 '22 at 04:50
  • 1
    This [answer you link](https://stackoverflow.com/a/18344096/16831808) is totally obsolete, `javafxpackager` doesn’t even exist in modern JDK distributions. Just follow the instructions at openjfx.io, or [packaging info in the JavaFX tag](https://stackoverflow.com/tags/javafx/info) not other sources. – jewelsea Jun 19 '22 at 04:53
  • 1
    You say you created “Java with Modular” but you didn’t. A modular JavaFX app requires Java 11+, it also needs a module info, and the module name and path needs to be provided when executing the app, none of which you have. – jewelsea Jun 19 '22 at 04:57
  • A modular jar file does not reference a main class in a manifest. Instead the jar command needs to be run to [set the main class for the module](https://jenkov.com/tutorials/java/modules.html#setting-the-jar-main-class). – jewelsea Jun 19 '22 at 05:01
  • It is recommended to use jlink or jpackage for packaging JavaFX applications for distribution. I recommend that you look into resources for using those tools rather than trying to build an executable jar file. – jewelsea Jun 19 '22 at 05:02
  • thanks, responding to your responses in order: 1. I'm not using JDK 8. Where did I say I was using JDK 8? – Patrick Abbey Jun 19 '22 at 18:58
  • 2. I think that's what the answerer I linked was getting at; I have to use their ways of packaging 3. I did create Java with Modular. I made sure I did. I have Java 17, like I said. It did have module info. 4. Good to know. 5. JLink only creates a runtime environment, I haven't found a use for it in deployment if I have to package the jar in the runtime environment anyway – Patrick Abbey Jun 19 '22 at 19:06
  • `JRE 1.8.xxx` is considered `Java8`. – SedJ601 Jun 20 '22 at 04:02
  • Here is what you need to do. `1.` Make sure you are using one of the latest versions of [`Java`](https://jdk.java.net/18/). Test using `java -version` in the command prompt. `2.` From there, follow one of the flows from [here](https://openjfx.io/openjfx-docs/). Do not attempt to use `ANT`! – SedJ601 Jun 20 '22 at 04:07
  • The tutorial shows an option for ANT actually. Also JRE 1.8 is considered Java 8, yes, but not JDK8 like Jewelsea said. – Patrick Abbey Jun 20 '22 at 07:36
  • Under which flow do you see an option for `ANT`? – SedJ601 Jun 20 '22 at 15:12

0 Answers0