有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java moduleinfo当我的一个外部库没有moduleinfo时

我是Java编码的初学者,我正在自学JavaFX,并制作一个通过Hibernate使用JPA的项目(我还没有Spring方面的知识)。 我发现自己的问题是,一个基本的外部库没有模块信息供我在项目中参考

我可以让JavaFX或mysql连接器java工作,但不能同时让两者工作。 我使用的连接器是:https://mvnrepository.com/artifact/mysql/mysql-connector-java版本8.0.19

当我排除模块信息时,我的JPA有效,当我使用模块信息时,我的FX有效

我向老师寻求帮助,但他似乎还不知道如何在同一个项目中使用JavaFX和JPA。有人对我如何解决这个问题有好的建议吗

我的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>

我的模块。信息

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

提前谢谢你的建议


共 (1) 个答案

  1. # 1 楼答案

    回答标题:

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

    您需要(在module info.java中)与依赖项jar的名称(没有版本)或jar的Automatic-Module-Name中声明的MANIFEST(如果存在)相对应的自动模块名称。然后maven会自动将jar添加到 module-path

    如果您不需要模块信息中的jar,它将被添加到 classpath中,在这种情况下,它将成为未命名模块的一部分,并且不会被您的模块看到(仅由自动模块看到)

    您可以将-X添加到maven以查看哪些依赖项添加到-classpath以及哪些依赖项添加到 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