Error: Hash of java.xml (…) differs to expected hash (…) recorded in java.base

对着背影说爱祢 提交于 2021-02-07 18:42:46

问题


Creating simple javafx 11 "hello world" application. Getting error while creating custom JRE.

user@user:~/Desktop/javafx/hellofx$ ./run.sh 
Error: Hash of java.xml (c043b4c28b897656e2a4d36c92ba2f5d52134bce79643236dd36295e14178be7) differs to expected hash (4e7db7fc941d9f316c4aafe02717b5809ee722be8433d283050365e7fd49331f) recorded in java.base

Error Code:

$JAVA_HOME/bin/jlink --module-path $PATH_TO_FX_MODS:mods --add-modules hellofx --output hellofx #error

OS: ubuntu 19.10

$java --version openjdk 11.0.6 2020-01-14 OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu119.10.1) OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu119.10.1, mixed mode, sharing)

$javac --version javac 11.0.6

user@user:~/Desktop/javafx/hellofx$ tree
.
├── mods
│   └── hellofx
│       ├── hellofx
│       │   └── HelloFX.class
│       └── module-info.class
├── run.sh
└── src
    ├── hellofx
    │   └── HelloFX.java
    └── module-info.java

5 directories, 5 files

run.sh:

user@user:~/Desktop/javafx/hellofx$ cat run.sh 
export PATH_TO_FX=/home/sameep/javafx-sdk-11.0.2/lib
export PATH_TO_FX_MODS=/home/sameep/javafx-jmods-11.0.2
javac --module-path $PATH_TO_FX -d mods/hellofx $(find src -name "*.java")

java --module-path $PATH_TO_FX:mods -m hellofx/hellofx.HelloFX

$JAVA_HOME/bin/jlink --module-path $PATH_TO_FX_MODS:mods --add-modules hellofx --output hellofx #error
#hellofx/bin/java -m hellofx/hellofx.HelloFX

module-info.java:

user@user:~/Desktop/javafx/hellofx/src$ cat module-info.java 
module hellofx {
    requires javafx.controls;

    exports hellofx;
}

HelloFX.java:

user@user:~/Desktop/javafx/hellofx/src/hellofx$ cat HelloFX.java 
package hellofx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;


public class HelloFX extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(new StackPane(l), 640, 480);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

}

Screenshot of output window


回答1:


As you could follow in the links such as this, this and this. It is more likely a JDK build issue and reverting to an older java.version e.g. 11.0.2 should fix this.

You can subscribe in the meanwhile to openjdk-build/issues/1214 for further updates.


When could this occur and what could cause this?

This could occur if the jmod files created for a module are not consistent in generating the hash. You can refer to the JMOD tool documentation which elaborates on one of the arguments responsible for this

--hash-modules regex-pattern

Determines the leaf modules and records the hashes of the dependencies directly and indirectly requiring them, based on the module graph of the modules matching the given regex-pattern. The hashes are recorded in the JMOD archive file being created, or a JMOD archive or modular JAR on the module path specified by the jmod hash command.

and furthermore in a subsided section describes

... This let’s you to allow a package to be exported to one or more specifically-named modules and to no others through qualified exports. The runtime verifies if the recorded hash of a module matches the one resolved at run time; if not, the runtime returns an error.



来源:https://stackoverflow.com/questions/60904135/error-hash-of-java-xml-differs-to-expected-hash-recorded-in-java-ba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!