0

Greetings

I have a JavaFX project that has a dependency on JAXB APIs that I developed using Netbeans 12.0, JDK 14.0 on Windows 10. Since JAXB APIs migrated from Java SE to JEE, they reside in an external javaee-api-6.0 jar file within the Netbeans installation directory. I have managed to compile and run the project within the IDE, however, I have created a jar for this project and I am trying to run it from the Windows command prompt (outside of the IDE). I leveraged this invaluable resource to get started (https://stackoverflow.com/questions/55652036/how-to-start-javafx-11-application-outside-ide/55653652#55653652), however, my scenario slightly varies.
Here is my module-info:

module org.openjfx.mavenfxedittableview {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.base;
    requires java.prefs;
    requires transitive java.xml.bind;
   
    opens org.openjfx.mavenfxedittableview to java.xml.bind, javafx.fxml;
    exports org.openjfx.mavenfxedittableview;
    
}


Here is the JAXB related dependencies in the pom.xml:

   <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.1</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>


I have copied the javaee-api-6.0.jar from the Netbeans into C:\MyLibs directory and created a system environment variable that is included in the system classpath:

JAVA_EXT=C:\MyLibs


I have jarred the project with the META-INF/MANIFEST.MF pointing to the main class:

Main-Class: org.openjfx.mavenfxedittableview.TableEditApp


Here is the import statement in my main class that pulls in the JAXB (java.ml.bind):

import javax.xml.bind.JAXBContext;


Here is the content of my jar file:

0 Tue Sep 08 07:34:02 IRDT 2020 META-INF/
   125 Tue Sep 08 07:34:02 IRDT 2020 META-INF/MANIFEST.MF
  2502 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/addressBookData.xml
  9562 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/Address_Book.png
   859 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/birthdaystatistic.fxml
  2602 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/BirthdaystatisticController.class
  3224 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/DarkTheme.css
  1824 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/DateUtil.class
   967 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/LocalDateAdapter.class
  2962 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/Person.class
  4535 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/personeditdialog.fxml
  4566 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/PersoneditdialogController.class
   839 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/PersonListWrapper.class
  6412 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/personoverview.fxml
  1904 Sat Sep 05 15:19:46 IRDT 2020 org/openjfx/mavenfxedittableview/rootlayout.fxml
  3741 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/RootlayoutController.class
  7433 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/TableEditApp.class
  5966 Sun Sep 06 18:34:38 IRDT 2020 org/openjfx/mavenfxedittableview/TableVieweditController.class
   349 Tue Sep 08 07:34:04 IRDT 2020 module-info.class


Here is the java command I use to run the jar file for the module:

java -p "%JAVAFX_HOME%\lib;%JAVA_EXT%;org\openjfx\mavenfxedittableview" -m org.openjfx.mavenfxedittableview


Here is the system error response:

C:\Users\hrh74\Downloads\Lib\table>java -p "C:\Program Files\java\jFX\javafx-sdk-14.0.2.1\lib;c:\MyLib\;org\openjfx\mavenfxedittableview" -m org.openjfx.mavenfxedittableview
Error occurred during initialization of boot layer
java.lang.module.FindException: Module java.xml.bind not found, required by org.openjfx.mavenfxedittableview

Any idea, how to include an external jar file, when running a module from the command line, so it can be found?

Update 1:

I have run the following command to find out the module name for the javaee-api-6.0.jar file.
jar --file=javaee-api-6.0.jar --describe-module | more

The module name for the jar file is javee.api as accurately predicated by slaw in the comments.

No module descriptor found. Derived automatic module.

javaee.api@6.0 automatic

I updated my module-info file with this module name, however, I the Netbeans IDE warns that it cannot find this module, thought the actual javaee-jar-6.0.jar is in the Netbeans internal library and part of the project classpath. enter image description here

Despite, the warning, the project compiles but at runtime (within the IDE and not the command prompt, which is my goal) it displays an error when it tries to use the JAXB APIS. If I supplant javaee.api with java.xml.bind in the "opens" statement of module-info then everything works within IDE (not the command prompt).

If, I don't make any modification in the module-info file and just try to run the application jar file from the command line using module name javaee.api for the javaee-api-6.0.jar file:

java -p "C:\Program Files\java\jFX\javafx-sdk-14.0.2.1\lib;c:\MyLib" --add-modules javafx.controls,javaee.api -jar org\openjfx\mavenfxedittableview\mavenfxedittableview.jar

Then I receive the following response:

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules javaee.api and java.xml export package javax.xml.stream.util to module javafx.swt


Thanks in advance.

Anthony
  • 135
  • 1
  • 14
  • You need to place the `javaee-api-6.0.jar` on the `--module-path` and declare the appropriate `requires` directive in your module descriptor. However, the module name won't be `java.xml.bind` but will instead be derived from the JAR file's name due to the JAR file being [an automatic module](https://stackoverflow.com/questions/46741907). Also, the name of your JAR file indicates it contains **all** the Java EE APIs, not just JAXB. Since you're using Java 11+ I recommend downloading the JAXB dependency for Java 11+ which _is_ modularized or using Maven or Gradle to do the same. – Slaw Sep 08 '20 at 23:45
  • @Slaw: Thanks for the insight. (1) In regards to having javaee-api-6.0.jar on the --module-path, I have already specified its location "c:\MyLib" in the -p switch. Do I have to do anything special? (2) I have also updated my post with the snippet of my pom that pulls in the JAXB related dependencies from the repository, isn't that enough? (3) Finally, do I need to manually turn the javaee-api-6.0.jar into an automatic module or does java command process takes care of it under the cover? – Anthony Sep 09 '20 at 02:22
  • I also tried to specify the javaee-api-6.0, using this form: java -p "C:\Program Files\java\jFX\javafx-sdk-14.0.2.1\lib;c:\MyLib" --add-modules javafx.controls,javaee-api-6.0 -jar org\openjfx\mavenfxedittableview\mavenfxedittableview.jar Error occurred during initialization of boot layer java.lang.module.FindException: Module javaee-api-6.0 not found – Anthony Sep 09 '20 at 02:52
  • There's an algorithm for determining the module name from the JAR file name and it's described [here](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/module/ModuleFinder.html#of(java.nio.file.Path...)). Basically, I'd expect when `javaee-api-6.0.jar` is an automatic module (with no `Automatic-Module-Name` manifest attribute) that the module name would be `javaee.api`. But if you are using Maven to pull in JAXB then I'm not sure why you have the `javaee-api-6.0.jar` in the first place? – Slaw Sep 09 '20 at 02:58
  • Side note: [This answer](https://stackoverflow.com/a/46715853/6395627) shows a way to utilize the `jar` tool to determine the name of an automatic module so you don't have to derive it yourself. – Slaw Sep 09 '20 at 03:01
  • @Slaw: Thanks for all the good helpful information. I tried to use the module name and added "Update 1" section to my post with the new error msg, which means I am getting further :-) – Anthony Sep 09 '20 at 06:21
  • Glad you're making progress. But as I mentioned before, if you have JAXB declared as a dependency in Maven then I'm not sure why you need the `javaee-api-6.0.jar` file. In other words, it seems like the problem you're having doesn't need to be solved; you just need to use the JARs downloaded from Maven Central. – Slaw Sep 09 '20 at 15:26
  • @Slaw: I spent some time and read all the links you have been providing in the past a few days and now I understand the concept of Module (new to Java, Netbeans but a quick learner hahaha) and everything sunk-in. I am very close to running this bad boy from the command line. As you suggested, I abandoned the javaee and pointed my java -p switch to the .m2 directory (Maven Repo). Gladly, I passed all the rudimentary errors. Now, I am grappling with "java.lang.module.FindException: Module org.jvnet.staxex not found, required by com.sun.xml.bind". Thanks so much. I keep you posted. – Anthony Sep 09 '20 at 16:33
  • @Slaw: Finally, I got it running from the command line. Now I go and work on packaging it with jpackage. Thank you for everything. – Anthony Sep 09 '20 at 18:33

0 Answers0