-1

I am building a java application but, Everytime I want to export to jar file the terminal show this error and my jar file are not executable. However if I run from VS code it doesn't show any error. This are the error I got when I want to export to jar file

[WARNING] duplicate entry: module-info.class

In my launch.json{}

"version": "0.2.0",
"configurations": [
        {
            "type": "java",
            "name": "Launch SpaceInvaders",
            "request": "launch",
            "vmArgs": "--module-path C:/JavaJdk/javafx-sdk-17.0.1/lib --add-modules javafx.controls,javafx.fxml",
            "mainClass": "Application.SpaceInvaders",
            "projectName": "Space_a536e277"
        },
        {
            "type": "java",
            "name": "Launch SpaceShooter",
            "request": "launch",
            "mainClass": "Application.SpaceShooter",
            "projectName": "Space_a536e277"
        },
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Launch App",
            "request": "launch",
            "mainClass": "Application.App",
            "projectName": "Space_a536e277"
        }
]

If I create module-info.java in my src file there is an error saying

module application {
     requires javafx.controls;
     requires javafx.fxml;
     exports application;
}

javafx.controls cannot be resolved to a module

Osanda Gamage
  • 446
  • 2
  • 6
  • 16
Osborne
  • 3
  • 5
  • "This are the error I got when I want to export to jar file" -> how do you export? What, exactly, does the export do? Is it trying to place the JavaFX modules (or other modular jars besides your application) in the jar file? If so, that would be a problem, because a [jar file can only contain a single module](https://stackoverflow.com/questions/47875351/multiple-java-9-modules-from-a-single-maven-module). – jewelsea Jan 18 '22 at 22:08
  • "there is an error saying . . . javafx.controls cannot be resolved to a module" -> when does that error occur? What are you doing to generate it? – jewelsea Jan 18 '22 at 22:17
  • There is a guide to [setting up JavaFX on VS Code](https://stackoverflow.com/questions/54349894/javafx-11-with-vscode), though I don't use VS code, so I don't know if that will assist you in this case. – jewelsea Jan 18 '22 at 22:19
  • I switch my IDE to eclipse .. the error still occur but my jar file are executable through cmd the code are still the same the difference only eclipse provide module-info.java but when i create module-info.java in vscode there is an error which fxml cannot be converted to module i thing iam not sure. If i use VSCODE my jar file still cannot execute through cmd and says class not found – Osborne Jan 19 '22 at 19:10
  • If you use maven for building, there is a guide to creating (an unsupported configuration) for a cross-platform jar in the answer to: [Maven Shade JavaFX runtime components are missing](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing). It will still generate various warnings as JavaFX is built to run as a modular system, but it will probably work, at least with JavaFX 17. – jewelsea Jan 20 '22 at 22:46

1 Answers1

0

I'm not sure about VS code's setup but ya in case of other IDE's like IntelliJ idea or eclipse you can add your.jar files in the project's additional java referential libraries section and you can simply switch your module to kind of application your are building(EE,FX)

  • My problem solve if i switch to eclipse even though the error are still there but it makes my jar file executable – Osborne Jan 19 '22 at 19:11