在我的多模块项目中,我module-info.java只创建了几个模块.在编译期间maven-compiler-plugin:3.7.0我得到下一个警告:
[警告]*检测到必需的基于文件名的自动模块.请不要将此项目发布到公共工件库!*
这是什么意思?是因为我只有几个模块,module-info.java而不是整个项目?
我有一些java9模块使用的第三方库不是Java9模块,只是一个简单的实用工具jar.
但是,编译器抱怨它无法从我的实用程序中找到包.
我应该怎么做module-info.java才能使用我的第三方库?
具有依赖于自动模块的显式模块化项目,例如,依赖于java.activation。仍然可以使用jlink吗?
请参阅以下module-info.java:
module hello {
requires java.activation;
}
Run Code Online (Sandbox Code Playgroud)
然后,Jlink无法添加模块:
$ jlink --module-path target/modules --add-modules hello --output target/jlink
Error: automatic module cannot be used with jlink: java.activation from file:///C:/Development/jlinkExample/target/modules/javax.activation-api-1.2.0.jar
Run Code Online (Sandbox Code Playgroud)
根据我的理解,自动模块无论如何都将包含整个类路径,所以我猜想用jlink创建运行时映像没有好处吗?另请参阅:什么是自动模块?
有没有可能解决这个问题的方法,也许为那些依赖项生成一个模块信息?
我有一个使用Kotlin Gradle插件的Gradle项目.我想构建一个Java 9模块,所以我的目录结构如下所示:
src/main/java/
- module-info.java
src/main/kotlin/
- Foo.kt
- Bar.kt
build.gradle
...
Run Code Online (Sandbox Code Playgroud)
我build.gradle声明了以下依赖项:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.10"
compile "org.jetbrains.kotlin:kotlin-reflect:1.2.10"
compile "org.junit.jupiter:junit-jupiter-api:5.0.2"
}
Run Code Online (Sandbox Code Playgroud)
我用所有这些依赖于我的科特林源(Foo.kt,Bar.kt,...).
如果我module-info.java这么写,那么一切都很有效:
module my.module {
requires kotlin.stdlib;
exports my.module.pkg;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用这种技术javac在compileJava任务期间提供所有编译时依赖项.
但是,如果我-Xlint:all在compileJava任务期间(编译module-info.java)打开Java编译器,我会收到以下警告:
/path/to/my.module/src/main/java/module-info.java:26: warning: requires directive for an automatic module
requires kotlin.stdlib;
^
Run Code Online (Sandbox Code Playgroud)
所以这里我们有Java编译器,javac抱怨这kotlin.stdlib是一个自动模块,所以我不应该有requires它的子句.
但是,如果我删除该requires条款以使其变得javac快乐,那么它就会kotlinc变得更加愤怒 …
我通过 Maven 存储库选择了 Apache Commons IO、JSerialComm 和 Ini4J 库。
但是当我尝试通过创建图像时mvn javafx:jlink出现以下错误:
[INFO] --- javafx-maven-plugin:0.0.2:jlink (default-cli) @ JUSBPlotter ---
[WARNING] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
Error: automatic module cannot be used with jlink: ini4j from file:///root/.m2/repository/org/ini4j/ini4j/0.5.4/ini4j-0.5.4.jar
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:447)
Run Code Online (Sandbox Code Playgroud)
我似乎与此有关:
Error: automatic module cannot be used with jlink:
Run Code Online (Sandbox Code Playgroud)
我的模块文件如下所示:
module org.openjfx.JUSBPlotter {
requires …Run Code Online (Sandbox Code Playgroud) 我正在使用 JavaFX,并且有一些不是自动模块的依赖项。当尝试运行时,mvn clean javafx:jlink我收到以下错误:
Error: automatic module cannot be used with jlink: org.apache.commons.io from [...]`
Run Code Online (Sandbox Code Playgroud)
这对于org.apache.commons.commons-lang3和也产生了错误commons-codec.commons-codec。我看到的错误是随机的。
所以我研究使用 jdeps 来生成依赖项的模块信息,例如
jdeps --generate-module-info tmp .../.m2/repository/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar
Run Code Online (Sandbox Code Playgroud)
然后我使用 Moditect 将模块信息添加到现有的 jar 中:
Error: automatic module cannot be used with jlink: org.apache.commons.io from [...]`
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的错误。
我的模块信息:
jdeps --generate-module-info tmp .../.m2/repository/commons-io/commons-io/2.12.0/commons-io-2.12.0.jar
Run Code Online (Sandbox Code Playgroud)
我的完整 pom.xml:
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Final</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>generate-resources</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<modules>
<module>
<artifact>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.12.0</version>
</artifact>
<moduleInfoSource>
module org.apache.commons.io {
exports org.apache.commons.io;
exports …Run Code Online (Sandbox Code Playgroud) 如果引用设置了“Automatic-Module-Name”的自动模块,为什么 Java 9 编译器会警告“module-info.java自动模块需要指令”?此类模块有什么风险?
这个问题与什么是自动模块?因为后者没有解决我引用的编译器警告背后的具体原因(问题的上下文很重要)。也就是说,这是后续阅读的有用链接。
我遵循了Gradle指南来构建Java 9模块,从而使一个简单的基于Java 9的库项目成为现实。特别是,我按照指南中的建议手动设置了模块路径,如下所示:
ext.moduleName = 'com.foo.bar'
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这只是获取我的整个类路径(由Gradle从我的依赖图中确定),并将其移到模块路径中。
除了一个简单的问题以外,一切工作都很好。我的某些依赖项(例如 org.jetbrains.kotlin:kotlin-stdlib-1.2.10)不是真正的Java 9模块,因为它们缺少module-info.class。它的优良坚持他们的类路径上或模块路径,因为,现在,java将它们转换成所谓的自动模块。
问题就出现了,因为即使是一个自动模块,如果是我的模块的道路上,我需要参考它在requires指令中我的项目的模块。但是由于我-Xlint:all选择了Java编译器,因此会javac产生以下警告:
/path/to/myproject/foo-module/src/main/java/module-info.java:26: warning: requires directive for an automatic module
requires kotlin.stdlib;
^
Run Code Online (Sandbox Code Playgroud)
这个警告对我来说是站不住脚的,因为我也随该-Werror javac标志滚动,因此它使我的构建失败。
因此,似乎我需要将自动模块推送到我的类路径上,并仅在模块路径上保留“ true”模块依赖项...
是否有任何通用或半通用的方式(即未与依赖项名称耦合)在编译器类路径及其模块路径之间拆分我的依赖项?
classpath gradle java-platform-module-system java-9 module-path
在阅读到可以长期支持OpenJDK 11之后,我决定创建一个小应用程序(使用Gradle)与JavaFX结合起来测试一些功能。经过一番努力,我设法创建了一个可以正常打开的Hello World .jar文件。
现在,我要进行下一步:运行.jar文件,而无需事先下载任何与Java相关的内容,因为由于必须正确设置PATH等,此刻安装OpenJDK很小。
关于将OpenJDK 11应用程序与Java 11 JRE捆绑在一起的搜索不会返回很多答案。我觉得这很奇怪,因为(据我了解)OpenJDK 11是第一个不附带JRE的产品。
所以我的问题是:如何结合运行时来交付Java 11应用程序?
我正在开发用于屏幕录制的 JavaFX 项目。我需要录制整个屏幕。我使用依赖。monte-screen-recorder
这是我的pom.xml文件:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.screenRecorder</groupId>
<artifactId>ScreenRecorder</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ScreenRecorder</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
</properties>
<dependencies>
<!-- JavaCV dependencies -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.jcodec</groupId>
<artifactId>jcodec-javase</artifactId>
<version>0.2.3</version>
</dependency>
<!-- JavaFX dependencies -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.stephenc.monte/monte-screen-recorder -->
<dependency>
<groupId>com.github.stephenc.monte</groupId>
<artifactId>monte-screen-recorder</artifactId>
<version>0.7.7.0</version>
</dependency>
<dependency>
<groupId>com.github.kokorin.jaffree</groupId>
<artifactId>jaffree</artifactId>
<version>2023.09.10</version>
</dependency>
</dependencies>
<build> …Run Code Online (Sandbox Code Playgroud) 我有一个按预期工作的 JavaFX 应用程序。我需要使用 Apache POI 来读取和写入 excel 文件。以下是我已采取的步骤:
添加了所需的依赖
implementation 'org.apache.poi:poi-ooxml:5.2.3'
将模块添加到 module-info.java
requires org.apache.poi.ooxml;
尝试在函数中使用该库:
@FXML
private void downloadTemplate() {
XSSFWorkbook workbook = new XSSFWorkbook();
}
Run Code Online (Sandbox Code Playgroud)
这一切都很好,没有任何问题。但是,当我尝试运行该应用程序时,出现以下两个错误(互换)
> Task :Start.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module SparseBitSet not found, required by org.apache.poi.ooxml
Run Code Online (Sandbox Code Playgroud)
和
> Task :Start.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module commons.math3 not found, required by org.apache.poi.ooxml
Run Code Online (Sandbox Code Playgroud)
我正在使用 IntelliJ Community Edition 2022.1.2 并使用 Java 17.0.1 运行该项目。任何帮助将不胜感激。
我使用gradle创建了一个带有intelliJ的java 10项目.我复制了一些东西(一些使用库guava和javaFx的"AppFx"类,以及一个个人的build.gradle文件).我还在src/main/java中添加了一个module-info.java文件,其中包含以下内容:
module biblio5.main {
requires javafx.graphics;
requires javafx.controls;
requires javafx.base;
requires guava;
}
Run Code Online (Sandbox Code Playgroud)
其中grava是一个自动模块.
这是build.gradle的相关部分:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.guava:guava:23.0'
}
Run Code Online (Sandbox Code Playgroud)
intelliJ可以编译项目(使用类似锤子的图标)但是当我从intelliJ运行compileJava gradle任务时,我收到一个错误:
13:12:46:执行任务'compileJava'......
任务:compileJava FAILED C:\ Users\lolve\Documents\gradle_java\biblio5\src\main\java\module-info.java:5:错误:找不到模块:guava需要guava; ^ 1错误
我花了很多时间在网上,但没有找到答案.
谢谢
ps:这是整个build.gradle:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
classpath 'eu.appsatori:gradle-fatjar-plugin:0.3'
}
repositories {
maven {url "https://mvnrepository.com/artifact/de.dynamicfiles.projects.gradle.plugins/javafx-gradle-plugin"}
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
jcenter()
}
}
plugins {
id 'java'
id 'application'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
apply …Run Code Online (Sandbox Code Playgroud) java ×9
java-9 ×4
java-platform-module-system ×4
javafx ×4
gradle ×3
jlink ×3
maven ×3
java-module ×2
apache-poi ×1
classpath ×1
gluon ×1
guava ×1
java-11 ×1
javafx-11 ×1
javafx-17 ×1
kotlin ×1
maven-3 ×1
moditect ×1
modularity ×1
module-path ×1