问题
My JavaFx project is working properly in intellij idea. In edit configurations, I have chosen the main class as sample.Main
and when clicking the run button of intellij idea, project works properly.
Then I have converted my JavaFX project to a .jar file using build artifacts. But when trying to run .jar by using java -jar project.jar
, there is an error "Missing JavaFX application class sample.Main". I have used same class in both occasions. So why does it output error while running .jar?
回答1:
Finally this worked for me. File-->Project Structure-->Artifacts-->press + button -->Add JAR-->From modules with dependencies. Now there will apear interface called create JAR from modules. Choose your exact Main Class there. Choose option "copy to the output directory and link via manifest". Directory for META_INF/MANIFEST.MF usually takes to java directory. It is good if you choose resources directory. Then click OK. A new window will appear.Click Apply and OK.Now go to the tool bar and click Build-->Build Artifacts-->Build.You can find built artifacts under the "project compiler output path".If you don't know exact location for "project compiler output path",then go File-->Project Structure-->Project-->Project compiler output. At the end of the project compiler output path you can see "artifacts" folder.There you can find a folder which consists all built jars.Right click the folder and click the "Show in Files".You can go to the exact folder having your built jars easily. Then open the terminal there and run "java -jar project.jar".project must be replaced by your application name.
来源:https://stackoverflow.com/questions/47411525/missing-javafx-application-class-sample-main