【问题标题】:module-info when one of my external libraries doesn't have a module-info当我的外部库之一没有模块信息时的模块信息
【发布时间】:2020-07-07 20:37:09
【问题描述】:

我是 Java 编码的初学者,我正在自学 JavaFX,并制作了一个通过 Hibernate 使用 JPA 的项目(我还不了解 Spring)。 我发现自己遇到的问题是,一个重要的外部库没有可供我在项目中引用的模块信息。

我可以让 JavaFX 或 mysql-connector-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;}

提前感谢您的任何建议

【问题讨论】:

标签: java mysql hibernate maven javafx


【解决方案1】:

回答题目:

当我的外部库之一没有模块信息时的模块信息

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

如果您不需要 module-info 中的 jar,它将被添加到 --classpath 在这种情况下,它将成为未命名模块的一部分,并且您的模块不可见(仅对自动模块) .

您可以将-X 添加到maven 以查看哪些依赖项添加到-classpath 以及哪些依赖项添加到--module-path

See the spec

[...]一个命名的模块,事实上,甚至声明对未命名的模块的依赖。这种限制是有意的,因为允许命名模块依赖于类路径的任意内容会使可靠的配置变得不可能

【讨论】:

    猜你喜欢
    • 2014-05-09
    • 2020-05-01
    • 2019-03-06
    • 1970-01-01
    • 2020-05-10
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多