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