我正在尝试运行我创建的Java 9模块,它使用Log4j2 2.10.0.
我遇到的问题是我得到了一个
java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
Run Code Online (Sandbox Code Playgroud)
做的时候LogManager.getLogger().它发现LogManager类很好,但是当它new PropertiesUtil("log4j2.StatusLogger.properties")从内部进入调用时StatusLogger,它会得到上面的错误.
如何修复/找到解决方法?
添加信息:
堆栈跟踪:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
at org.apache.logging.log4j/org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71)
at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
at com.EvolutionarySoftwareSystems.Utilities/com.EvolutionarySoftwareSystems.Utilities.Base.DebugAble.<clinit>(DebugAble.java:45)
Run Code Online (Sandbox Code Playgroud)
更奇怪的是我可以直接调用invoke:new PropertiesUtil("string")从我的代码中找到类.
我正在使用日食氧气4.7.1a.
我的eclipse启动配置文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<setAttribute key="name.schedenig.eclipse.grepconsole.DisabledIds"/>
<setAttribute key="name.schedenig.eclipse.grepconsole.EnabledIds"/>
<setAttribute key="name.schedenig.eclipse.grepconsole.FilterDisabledIds"/>
<setAttribute key="name.schedenig.eclipse.grepconsole.FilterEnabledIds"/>
<setAttribute key="name.schedenig.eclipse.grepconsole.StatisticsDisabledIds"/>
<setAttribute key="name.schedenig.eclipse.grepconsole.StatisticsEnabledIds"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Evolver/src/com/EvolutionarySoftwareSystems/Evolver/Server/EvolServer.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers …Run Code Online (Sandbox Code Playgroud) 更新:我在这里回答了我自己的问题:
-
[旧问题 - 已过时:]
在Java 9中获取ModuleReference给定Module对象的正确方法是什么?
考虑以下两种方法java.base:
Module mod = ModuleLayer.boot().findModule("java.base").orElse(null);
ModuleReference modRef = ModuleFinder.ofSystem().find("java.base").orElse(null);
Run Code Online (Sandbox Code Playgroud)
mod有一个方法Set<String> getPackages(),但是你只获得包的名称,你不能列出每个包中的资源.
modRef有一个方法ModuleReader open(),并ModuleReader有一个方法Stream<String> list()列出模块中的资源,这是我需要做的.
但是,对于通过向类路径添加非模块jar文件而生成的自动(因此未命名)模块,您无法获取ModuleReferencefrom ModuleFinder.ofSystem().find(String name)或ModuleFinder.ofSystem().findAll()- 您只能从中获取Module引用getClass().getModule().
我找不到任何方法来获得ModuleReference自动模块.我也找不到ModuleReference从Module对象获取a的方法,这意味着Module如果模块是自动和/或未命名的,我无法列出资源.
当然必须有一种方法来获得ModuleReference一个给定的(已经加载)Module?
我正在尝试使用 jlink 工具来构建一个 java 可执行文件。我按以下方式使用它:
jlink.exe --module-path <path-to-modules> --add-modules <my-module-name> --output dist --launcher launch=org.demo/org.demo.Main --strip-debug --compress 2 --no-header-files --no-man-pages
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
Error: signed modular JAR <path-to-modules>\bcprov.jdk15on.jar is currently not supported, use --ignore-signing-information to suppress error
Run Code Online (Sandbox Code Playgroud)
当我添加“--ignore-signing-information”选项时,它可以很好地构建我的可执行文件,但它给了我以下警告:
WARNING: signed modular JAR <path-to-modules>\bcprov.jdk15on.jar is currently not supported
Run Code Online (Sandbox Code Playgroud)
然后,当我执行已经构建的可执行文件时,我收到以下异常:
org.apache.sshd.common.SshException: Failed (NoSuchProviderException) to execute: JCE cannot authenticate the provider BC
at sshd.core/org.apache.sshd.common.future.AbstractSshFuture.verifyResult(Unknown Source)
at sshd.core/org.apache.sshd.client.future.DefaultAuthFuture.verify(Unknown Source)
at sshd.core/org.apache.sshd.client.future.DefaultAuthFuture.verify(Unknown Source)
Caused by: java.util.jar.JarException: Non-Oracle JCE providers may not be linked into the image,they must be …Run Code Online (Sandbox Code Playgroud) jar-signing jlink java-platform-module-system java-9 java-module
sun.misc.Perf在tools.jar和在Java中这9取出并基于模块概念重组,因此,问题是你如何访问它在新的Java?我需要知道哪个模块现在包含此代码。
我想使用 netbeans 迁移到 Java 11 和 JFX11。JFX11 必须用作模块,所以我添加了 JavaFX jars 并在默认包文件夹下的 module-info.java 中添加了以下内容。
requires javafx.controls;
requires javafx.base;
requires javafx.fxml;
requires javafx.graphics;
requires javafx.swing;
requires java.logging;
requires java.desktop;
requires java.sql;
requires java.xml;
Run Code Online (Sandbox Code Playgroud)
这导致我的所有其他依赖项显示“pacakges 'xyz' 不可见......(包 'xyz' 在未命名的模块中声明,但模块 'xyz' 不读取它)”当我尝试清理和9.在netbeans中构建
我不能混合模块和库吗?我错过了什么?
java javafx java-platform-module-system java-module javafx-11
我喜欢服务。我也喜欢模块系统。对我来说不幸的是,在我使用 Java 9 之前,我养成了从运行时通过 jar 加载的 jar 获取服务提供者的习惯URLClassLoader,就像这样(var为了简洁,我将使用 Java 10 ):
var url = new File("myjar.jar").toURI().toURL();
var cl = new URLClassLoader(new URL[] {url}, getClass().getClassLoader());
var services = ServiceLoader.load(MyService.class, cl);
for (var service : services) {
...
}
Run Code Online (Sandbox Code Playgroud)
即使在 Java 9 及更高版本中,这也能正常工作,但它会将 jar 加载到类路径上,这意味着它使用旧META-INF\services方法来查找服务提供者。我宁愿使用该module-info方法,但这需要将 jar 加载到模块路径上,但我找不到任何方法来执行此操作。所以我在这里,希望这里的某个更彻底地了解模块系统的人会告诉我如何做到这一点(或者它不能,如果是这样的话)。
一个例子:由于 JavaFx 从 JDK 中删除,JavaFx SDK 现在作为一组模块化 jar 分发。要编译 JavaFx 应用程序,当然必须将它们放在模块路径中:
javac -p /path/to/jars/ App.java
Run Code Online (Sandbox Code Playgroud)
然而,这还不够。尝试编译会导致很多类似的错误
sample/App.java:3: error: package javafx.application is not visible
import javafx.application.Application;
^
(package javafx.application is declared in module javafx.graphics, which is not in the module graph)
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我们可以使用 --add-modules 添加 javafx.graphics:
javac -p /path/to/jars/ --add-modules javafx.graphics App.java
Run Code Online (Sandbox Code Playgroud)
但是,如果我们将 module-info.java(仅包含module ui {})添加到项目中,则没有问题。
为什么模块路径上的模块对命名模块可见,但对未命名模块不可见?
我试图了解使用 Java 平台模块系统 (JPMS) 构建项目与使用 multi-poms 构建项目之间的区别。
主要区别是 JPMS 封装代码而多 pom 项目分离项目依赖关系?
我在谷歌上搜索过,但没有找到对差异的很好解释,但我看到模块这个词可以互换使用。
我正在将生产代码中的 java 版本从 java 8 升级到 java 11。
由于使用了flume、zookeeper等第三方库,我必须在应用程序java start命令中添加以下JDK模块配置。
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
添加此配置后,java 应用程序启动正常。
但是当我使用mvn test测试运行测试时失败了。我已将以下配置添加到 maven-surefire-plugin 中,但它仍然抛出错误。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>--illegal-access=permit</argLine>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
<argLine>--add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED</argLine>
<argLine>-Dillegal-access=permit</argLine>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我想我没有在 maven 测试中正确地传递参数。知道我做错了什么以及如何解决这个问题吗?
我有一个简单的 JavaFX Web 浏览器,它是一个模块。该模块的目录结构为:
webBrowser
webBrowser/module-info.java
webBrowser/webbrowser
webBrowser/webbrowser/WebBrowser.java
Run Code Online (Sandbox Code Playgroud)
这是 module-info.java 的代码
module webBrowser {
requires javafx.controls;
requires javafx.web;
exports webbrowser;
}
Run Code Online (Sandbox Code Playgroud)
以下是 WebBrowser.java 的代码:
package webbrowser;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.scene.web.WebEngine;
import javafx.stage.Stage;
public class WebBrowser extends Application {
@Override
public void start(Stage stage) {
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.load("http://www.oracle.com");
Scene scene = new Scene(browser, 1200, 900);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Run Code Online (Sandbox Code Playgroud)
我用 javac 编译我的模块化应用程序: …
java-module ×10
java ×9
java-9 ×7
java-platform-module-system ×3
javafx ×2
jlink ×2
maven ×2
classpath ×1
jar-signing ×1
java-11 ×1
javafx-11 ×1
log4j2 ×1
module-info ×1
multi-module ×1