当使用ant, 调用sun.awt.AppContext工作时,但是使用 AdaptOpenJDK11 使用 IntelliJ 编译的相同代码失败。
sun.awt.AppContext使用Oracle JDK8与 IntelliJ 配合使用sun.awt.AppContext采用AdoptOpenJDK11不适用于IntelliJ尽管 Sun/Oracle 已经警告过一段时间要避免使用这些sun.*包,但Java中的某些功能(错误?)仍然需要它们,而且很奇怪,命令行似乎很高兴。
示例代码:
package test;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import sun.awt.AppContext;
public class Main {
public static void main(String[] args) {
//Update printer list in CUPS immediately
AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);
PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService p : printers) {
System.out.println(p.getName());
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何配置 IntelliJ 使其表现得像ant并允许访问sun.awt.* …
我在自定义 linux 硬件上使用自定义 Java 11 运行时,Java 运行时不是我构建的。但是我有一个问题,我的应用程序需要访问字体并且运行时没有配置任何字体,所以我得到了这个堆栈跟踪
Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.getFont2D(Font.java:497)
at java.desktop/java.awt.Font.getFamily(Font.java:1410)
at java.desktop/java.awt.Font.getFamily_NoClientCode(Font.java:1384)
at java.desktop/java.awt.Font.getFamily(Font.java:1376)
at java.desktop/java.awt.Font.toString(Font.java:1869)
at java.base/java.lang.String.valueOf(String.java:2951)
at java.base/java.io.PrintStream.println(PrintStream.java:897)
at Fonts.main(Fonts.java:7)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
... 10 more
Caused by: java.lang.NullPointerException
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:367)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:312)
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
Run Code Online (Sandbox Code Playgroud)
我可以提供一些字体,并且我已经计算出我需要创建一个fontconfig.properties并将我放入 Java runtimes …
预先感谢,谁将帮助我。
故事:到目前为止,我的应用程序正在使用JDK8,但是现在我正在将应用程序迁移到Open JDK11并IVY用作依赖项管理器和Ant构建工具。
问题:我在eclipse中遇到了编译时问题javax,但是后来我将构建路径中的JRE lib从classpath更改为Modulepath。现在一切正常。但是,现在的主要问题是,在运行antbuild.xml使用Ant,这仍然给我相同的编译时错误。我想,我知道该怎么办,但是我不知道该怎么办。我必须在中的Open JDK11某处添加模块路径antbuild.xml。
主要问题:如何Open JDK11在antbuild.xml(基本蚂蚁构建文件)中设置为模块路径。
如果问题仍然无法理解,请告诉我。
环境:
我scalafx-hello-world从GitHub签出了,并在IntelliJ中构建并运行了它,一切正常。这里快速介绍重要的应用程序实现:
package hello
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.effect.DropShadow
import scalafx.scene.layout.HBox
import scalafx.scene.paint.Color._
import scalafx.scene.paint._
import scalafx.scene.text.Text
object ScalaFXHelloWorld extends JFXApp {
stage = new PrimaryStage {
// initStyle(StageStyle.Unified)
title = "ScalaFX Hello World"
scene = new Scene {
fill = Color.rgb(38, 38, 38)
content = new HBox {
padding = Insets(50, 80, 50, 80)
children = …Run Code Online (Sandbox Code Playgroud) 我已经在 Ubuntu 机器上运行这个旧的 Caucho Resin (4.0.41) 很多很多年了。我需要退役该服务器,所以我尝试在新的 Ubuntu 18.04.4 服务器上设置resin 4.0.64,经过大量的尝试和摆弄,它正在启动,但最终在早期失败了:
OpenJDK 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "com.caucho.loader.SystemClassLoader"). To use archived non-system classes, this property must be not be set
Error occurred during initialization of VM
java.lang.Error: com.caucho.loader.SystemClassLoader
at java.lang.ClassLoader.initSystemClassLoader(java.base@11.0.6/ClassLoader.java:1989)
at java.lang.System.initPhase3(java.base@11.0.6/System.java:2069)
Caused by: java.lang.ClassNotFoundException: com.caucho.loader.SystemClassLoader
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@11.0.6/BuiltinClassLoader.java:581)
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@11.0.6/ClassLoaders.java:178)
at java.lang.ClassLoader.loadClass(java.base@11.0.6/ClassLoader.java:521)
at java.lang.Class.forName0(java.base@11.0.6/Native Method)
at java.lang.Class.forName(java.base@11.0.6/Class.java:398)
at java.lang.ClassLoader.initSystemClassLoader(java.base@11.0.6/ClassLoader.java:1975)
at java.lang.System.initPhase3(java.base@11.0.6/System.java:2069)
Run Code Online (Sandbox Code Playgroud)
我似乎无法通过谷歌搜索找到任何结果,也找不到任何明显的设置 java.system.class.loader。
有什么建议么?谢谢!
我有一个玩具程序,当我尝试使用 Chronicle 导入并编译到语言级别 11 时,该程序仅在 Eclipse 中出现编译错误。该程序在 maven 和 IntelliJ 中编译和运行(使用相同的 maven 和 JDK)。
我拥有的版本是:
这是我的 pom.xml
<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>testjava11</groupId>
<artifactId>chronicle-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>2.19.199</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的简单测试类:
import net.openhft.chronicle.bytes.BytesMarshallable;
public class App {
public static void main(String[] args) {
System.out.println("BytesMarshallable: " + new BytesMarshallable() {});
} …Run Code Online (Sandbox Code Playgroud) 所以我尝试在没有 Android Studio 的情况下安装 flutter,因为每当我尝试打开 Android Studio 时,我的电脑运行速度非常慢。一开始一切都很顺利,但是当 flutter 尝试使用 Android 许可证时
flutter doctor --android-licenses
Run Code Online (Sandbox Code Playgroud)
它总是给我
C:\Windows\System32>flutter doctor --android-licenses
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to
resolve this.
Run Code Online (Sandbox Code Playgroud)
当我检查使用时
flutter doctor --android-licenses -v
Run Code Online (Sandbox Code Playgroud)
它给我
C:\Windows\System32>flutter doctor --android-licenses -v
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to
resolve this.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 AndroidLicenseValidator.runLicenseManager (package:flutter_tools/src/android/android_workflow.dart:422:7)
#2 Doctor.diagnose (package:flutter_tools/src/doctor.dart:295:38)
#3 DoctorCommand.runCommand …Run Code Online (Sandbox Code Playgroud) 我在服务器上运行 openjdk 11.0.3。每当服务器重新启动时(每晚):对于我的应用程序的第一次初始启动,用户必须等待 35 秒才能启动应用程序。(在从 main 方法编写第一个 System.out.println 之前。)(尽管后续启动非常快)我尝试了以下选项来调试它:
-Xlog:class+load:file=classload.txt
Run Code Online (Sandbox Code Playgroud)
以下是最重要的发现:
...
[2.284s][info][class,load] jdk.internal.loader.URLClassPath$FileLoader source: jrt:/java.base
[5.032s][info][class,load] sun.security.rsa.RSASignature$SHA1withRSA source: jrt:/java.base
…
[5.051s][info][class,load] java.util.LinkedList$Node source: jrt:/java.base
[8.121s][info][class,load] pos.LFChangeable source: file:/C:/Users/rho/AppData/Roaming/edapp/pos.jar
…
[8.135s][info][class,load] java.io.FileNotFoundException source: jrt:/java.base
[10.584s][info][class,load] sun.reflect.misc.ReflectUtil source: jrt:/java.base
…
[11.744s][info][class,load] java.security.NoSuchAlgorithmException source: jrt:/java.base
[34.853s][info][class,load] jdk.internal.logger.DefaultLoggerFinder source: jrt:/java.base
Run Code Online (Sandbox Code Playgroud)
为什么在加载 java.security.NoSuchAlgorithmException 和 jdk.internal.logger.DefaultLoggerFinder 之间挂起 23 秒?那么其他几秒钟的减速呢?
编辑:根据评论,我会澄清一些。这是一个 Windows rdp 服务器。实际上,它不止一台服务器,但问题仍然存在于所有服务器上。该应用程序是一个独立的应用程序。所以每天早上都会出现问题,因为登录启动应用程序的用户会在“没有任何反应”时尝试多次启动它。我现在已经多次尝试重新启动其中一台服务器,这就是我发现的:
重新启动后使用 java11 启动我的应用程序平均需要 40 秒,然后才会出现第一个 System.out.println。然后在我的第一个 JFrame 显示之前只有 1-2 秒。重新启动后使用 java8 (sun) 启动我的应用程序在第一个 System.out.println 之前平均需要 16 秒。但是在我的第一个 JFrame 显示之前,我得到了 25 秒的延迟。在已经使用 java8 …
在 java 8 中设置安全提供程序我只需要将提供程序添加到 java.security 文件并将提供程序外部库添加到 lib/ext。由于在其他版本中不允许使用外部库,如何在 jdk11 上添加提供程序?
到目前为止,我尝试将提供程序添加到 conf/security 文件夹中的 java.security 文件中。
security.provider.1=nCipherKM
Run Code Online (Sandbox Code Playgroud)
我在列表顶部插入了新的提供程序,但是当我尝试 .getInstance("providerExample") 时,我仍然收到 NoSuchProviderException。
java.security.NoSuchProvidIrException: no such provider: nCipherKM
Run Code Online (Sandbox Code Playgroud)
lib jar 本身,我不知道我必须把它放在哪里,或者我怎样才能包括它才能被识别。如果我创建一个 lib/ext 文件夹,他说要使用 -classpath ,但对此也一无所知。
谢谢
编辑:为了完成我的问题,我忘了提到我使用 thorntail 和 maven 3.6.1 来构建项目。我得到的错误与这一行有关:
KeyStore.getInstance("ncipher.sworld", "nCipherKM");
Run Code Online (Sandbox Code Playgroud)
正如我之前所说,当我有 java 8 时,我只需要将 security.provider 添加到 java.security 并将 nCipherKM.jar 添加到 $JAVA_HOME/lib/ext 文件夹。
我最近想尝试 Java,所以我从 Hello World 开始!我为 VSCode 安装了 OpenJDK 11 并运行了该程序,但它产生了以下错误:
Running the contributed command: 'java.execute.workspaceCommand' failed.
我查看了 Java 运行时配置,它检测到了 JDK,但它显示了错误!
openjdk-11 ×10
java ×8
java-11 ×4
adoptopenjdk ×1
android ×1
ant ×1
classloader ×1
classloading ×1
eclipse ×1
flutter ×1
fonts ×1
ivy ×1
java-platform-module-system ×1
module-path ×1
resin ×1
scala ×1
scalafx ×1