0

I have the following problem when trying to launch a .jar file of my program in cmd: no main manifest attribute, in path/filename.jar

I tried to add the Main-Class to the MANIFEST.MF file, but then it says Error: Could not find or load main class.

In NetBeans I have set the Main Class at Properties->Run->Main Class to the one, which holds the function main(String[] args) in my case "com.nxp.vda_with_gui_1.version.App". I have also added VM Options for the JavaFX modules like the following:

--module-path C:\NetbeansJavaFX --add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media

In NetBeans I can build and launch up my program without any errors, but when I try to "Run File" (Shift + F6) a different error will be put out:

Error: JavaFX runtime components are missing, and are required to run this application Command execution failed.

Any tips how to solve it?

Below you can find a picture of my file/package structure and some other information, maybe it helps finding a solution quicker:

jewelsea
  • 150,031
  • 14
  • 366
  • 406
Hubaaa
  • 1
  • 1
    You have multiple questions, one about running a main class from netbeans and another about running a jar from the command prompt. Please focus questions and just ask one thing in each question. – jewelsea Sep 08 '22 at 08:12
  • 1
    Your app is modular, it has a module-info. If you want to run a module, you [set the main class using the jar command](https://jenkov.com/tutorials/java/modules.html#setting-the-jar-main-class), not in the manifest. You also need to provide, on the command line, the module path to the JavaFX modules, and any other modules that you are require. – jewelsea Sep 08 '22 at 08:16
  • You may be better off using an execution script and jlink or jpackage for packaging. – jewelsea Sep 08 '22 at 08:18
  • @jewelsea both has something with my program, but what I want to achieve is to get a working executable .jar file of my program. The second part of my question might not be that much needed, but maybe it helps to find a solution easier. Thank you for your answers I will try it to set the main class with the jar commands and will look into jlink, since I never heard of it. – Hubaaa Sep 08 '22 at 08:24
  • @jewelsea I'm trying to compile the modules/packages, but I'm not sure which one the source root directory is. the current command I tried is: `javac -d compiled --module-source-path C:\TestExe\VDA_with_GUI_1.0-Version\src\main --module com.nxp.vda_with_gui_1.version,analysispackage` End this is the error msg: `error: module com.nxp.vda_with_gui_1.version not found in module source path error: module analysispackage not found in module source path` – Hubaaa Sep 08 '22 at 09:06
  • tried with `javac -d compiled --module-source-path C:\TestExe\VDA_with_GUI_1.0-Version\src\main\java --module com.nxp.vda_with_gui_1.version,analysispackage` , but still the same error – Hubaaa Sep 08 '22 at 09:38
  • I wouldn't compile from the command line with `javac`, you can do that, but it doesn't scale well and is error-prone. Instead, use your IDE to compile, or (better) use a build tool (either maven or gradle). I suggest using maven if you have used neither. All major IDEs integrate with the main build tools (though I haven't used NetBeans in a long time, so don't know the quality of its integration, I know Idea has good integration). – jewelsea Sep 08 '22 at 18:14
  • If it were me, I would [create a new JavaFX project in Idea](https://www.jetbrains.com/help/idea/javafx.html), choose maven as the build tool, and copy the project source into it. Then use the [javafx-maven-plugin](https://github.com/openjfx/javafx-maven-plugin) to jlink the app and create a zip for distribution. But what you do is up to you. – jewelsea Sep 08 '22 at 18:17
  • "what I want to achieve is to get a working executable .jar file of my program" -> if you mean a single jar that also includes the JavaFX modules, that is not supported. Though you can [make it work](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing), I don't advise it. – jewelsea Sep 08 '22 at 18:18
  • okay, thank you! I'll try to get it work in IntelliJ then and this might sound dumb but it is possible to make an actual program/software (which I can just start on a machine without an IDE, but Java installed) out of my project, right? – Hubaaa Sep 09 '22 at 09:42
  • Yes, that is possible, though I would advise packaging the app with jlink (if you don't want an installer) or jpackage (if you do want an installer), to remove the requirement for Java to be installed on the machine. Packaging info in the [javafx tag](https://stackoverflow.com/tags/javafx/info). – jewelsea Sep 09 '22 at 20:11

0 Answers0