Robust configuration in Java 9

One of the main goals of the Jigsaw project in Java 9 is to have a reliable configuration. . That is, Java 9 promises to eliminate the lack of a class path mechanism that allows you to run the java program without guaranteeing that all necessary classes will be available for loading at runtime, resulting in java.lang.NoClassDefFoundErrors.

This is done by declaring module dependencies in module-info.javaand new --module-path. The module graph is analyzed before starting the Java application.

However, I can still do the following.

  • Suppose I have two modules com.spacey.explorerand com.spacey.rocket. com.spacey.exploreruses the class com.spacey.rocket.RocketZdefined and exported by the module com.spacey.rocket. After compilation and JARING, both modules work correctly.
  • Now I remove the type com.spacey.rocket.RocketZfrom the module com.spacey.rocketand recompile and re-JAR only this single module.
  • I ran a previously compiled module com.spacey.explorerwith a newly compiled module com.spacey.rocket.
  • I get ... java.lang.NoClassDefFoundErrorwhat is possible after 4 hours of application operation.

Is there a way to really make sure that when starting a Java application, not only the completeness of the modular graph (the path to the module) is checked, but also a full check of the availability of this type?

+4
source share
2 answers

, Java ( ), ? p >

JVM, . , , , . , .

, JDeps . . , .

:

$ jdeps -R --module-path jars-dir -m com.spacey.explorer

> com.spacey.explorer    -> com.spacey.rocket    not found
+5

, , , , .

:

. , ClassLoaders , ClassLoader , .

, :

Java . , , - , .

: , , LinkageError ( No..FoundError thingies). . , .

: " " " ", Jigsaw .

+3

Source: https://habr.com/ru/post/1686508/


All Articles