0

I am a beginner in Java coding, I am teaching myself JavaFX and making a project that uses JPA through Hibernate (I have no knowledge on Spring yet). The problem I find myself having is that an essential external library doesn't have a module-info for me to refer to in my project.

I can have either JavaFX or mysql-connector-java working, but not both at the same time. The connector I am using is: https://mvnrepository.com/artifact/mysql/mysql-connector-java version 8.0.19

When I exclude my module-info my JPA works, when I use my module-info my FX works

I asked my teacher for help but he doesn't seem to have an idea yet on how I can use my JavaFX and JPA in the same project. Does anyone have a good suggestion on how I can fix this issue?

My POM

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.tumblr.calscodingcorner</groupId>
<artifactId>dnd5e_database_maker</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.3</version>
            <configuration>
                <mainClass>com.tumblr.calscodingcorner.application.App</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.6.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.4.12.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx</artifactId>
        <version>11</version>
        <type>pom</type>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
</dependencies>

My module.info

module dnd5e.database.maker {
requires javafx.controls;
requires java.persistence;
requires mysql.connector.java;
exports com.tumblr.calscodingcorner.application;}

Thanks in advance for any advice

  • 1
    [The source code](https://github.com/mysql/mysql-connector-j) is available so you could simply add the module-info yourself and build it or [add an entry to the manifest](https://stackoverflow.com/a/46742802/2991525). – fabian Mar 27 '20 at 06:28

1 Answers1

0

Answering the title:

module-info when one of my external libraries doesn't have a module-info

You need to require (in module-info.java) the automatic module name corresponding to the name of the dependency jar (without the version), or to the Automatic-Module-Name declared in the jar's MANIFEST (if exists). Then maven will automatically add the jar to --module-path.

If you don't require the jar inside module-info, it will be added to --classpath in which case it will become part of the unnamed module and won't be visible by your module (only by automatic modules).

You can add -X to maven to see which dependencies are added to -classpath and which to --module-path

See the spec

[...] A named module cannot, in fact, even declare a dependence upon the unnamed module. This restriction is intentional, since allowing named modules to depend upon the arbitrary content of the class path would make reliable configuration impossible

Marinos An
  • 9,481
  • 6
  • 63
  • 96