Questions tagged [java-9]

Use this tag for questions specific to Java 9, which is version 9 of the Java platform, released on the 21st of September 2017. In most cases you should also specify the java tag.

Oracle has released its updated list of proposed or targeted Java 9 enhancements. In addition to previously confirmed Java modularity updates, the most recent list includes a common logging system for all JVM components (JEP 158), more HotSpot JIT compiler controls (JEP 158), and refinements to improve the efficiency of garbage collection (JEP 214), and repair issues introduced by Project Coin language updates in JDK 7 (JEP 213). This is also the first release under the new version-string schema (JEP 223) and will hence be officially be numbered 9, not "1.9.0" as was the case for earlier versions.

Even with delays, Oracle has been steadily moving forward with its plans to modularize the JDK. But the scope of Java modularity took a step up in September, when Oracle announced four new JEPs, including JEP 220: Modular Run-Time Images. Ben Evans, writing for InfoQ, noted that swapping JARs for modules is the "point of no return for modularity," with serious implications for IDEs, toolmakers, and many Java application frameworks:

After this point, The Java Runtime Environment (JRE) will no longer be contained in jar files, and instead will be composed of modules (JSR 376). Files such as rt.jar and tools.jar no longer exist in the JRE. The platform will continue to accept and run applications and libraries packaged in conventional jar files, modular jar files, or in the new module file format. The intention is that over time, application developers wil migrate to the new modular formats as well.

See "Oracle Commit to Java Modularity" for more from Ben Evans on modularity updates in Java 9. Also see Takipi Blog: "Java 9 – The Ultimate Feature List" for a comprehensive (as of November 20, 2014) description of new features accepted or proposed for the next major release of Java, and "What's New in Java 9? (Besides Modules)" for another more recent compilation of features.

The API documentation of the release can be accessed at Oracle's technetwork.

1606 questions
28
votes
14 answers

Error occurred during initialization of boot layer FindException: Module not found

Executing a simple "Hello World" program using Java 9 results in the following error message: Error occurred during initialization of boot layer java.lang.module.FindException: Module com.pantech.myModule not found The command line that I…
D. Pante
  • 321
  • 1
  • 3
  • 6
28
votes
2 answers

Is Java 9 modularity for WAR files as well?

A Java EE 7 application server, and specifically a Servlet 3.1 container should allow us to deploy a WAR file that contains a web application. And a WAR file is essentially a JAR with deployment descriptor (web.xml) and couple of other elements. On…
malloc4k
  • 1,742
  • 3
  • 22
  • 22
28
votes
3 answers

How do you replace endorsed directory in Java 9?

In Java 8 and prior there exists the mechanism to use an endorsed directory(java.endorsed.dirs), which is a collection of libraries which overrides JDK internal implementations. How can I solve this in Java-9? As endorsed dirs where removed there?
keiki
  • 3,260
  • 3
  • 30
  • 38
28
votes
1 answer

Does the Java 9 Module system support optional dependencies?

Background In maven, an artifact can declare a dependency with true which means that the dependency is not required, but can be used if present. The State of the Module System seems to specify that a module can only read…
meriton
  • 68,356
  • 14
  • 108
  • 175
27
votes
3 answers

Is there a way to prevent ClosedByInterruptException?

In the following example, I have one file being used by two threads (in the real example I could have any number of threads) import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
27
votes
3 answers

Accessing resource files from external modules

So far until non-modularized java, you would simply put a file in src/main/java/resources make sure it is in classpath and then load it with file = getClass().getClassLoader().getResourceAsStream("myfilename"); from pretty much anywhere in the…
cen
  • 2,873
  • 3
  • 31
  • 56
27
votes
3 answers

List modules in jar file

I've created what I'm pretty sure is a modular jar file. But if possible, I'd like to double check. Given a jar file, is there a way to determine what modules the compiler would find within it?
PopKernel
  • 4,110
  • 5
  • 29
  • 51
27
votes
2 answers

How to get access to javax.annotation.Resource at run time in Java 9

I have a test: public class ResourceTest { @Test public void test() throws ClassNotFoundException { Class.forName("javax.annotation.Resource"); } } It tries to access javax.annotation.Resource. In java 8 it worked, but in java 9…
Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72
27
votes
6 answers

How to extract the file jre-9/lib/modules?

In JRE-9/lib directory (at least on Windows), there is a new file called modules whose size is about 107 MB. Is it possible to extract that file or maybe list java modules within it? I can see that a new tool called jmod is available at…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
26
votes
6 answers

Why does Set.of() throw an IllegalArgumentException if the elements are duplicates?

In Java 9 new static factory methods were introduced on the Set interface, called of(), which accept multiple elements, or even an array of elements. I wanted to turn a list into a set to remove any duplicate entries in the set, which can be done…
Benjamin
  • 533
  • 9
  • 27
26
votes
1 answer

Android SDK manager throw Exception with Java 9

Using sdk-tools-darwin-4333796 (26.1.1) with Java 9 when running sdkmanager is throwing : Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at…
Aero Wang
  • 8,382
  • 14
  • 63
  • 99
26
votes
2 answers

What's the difference between requires and requires static in module declaration

What's the difference between requires and requires static module statements in module declaration? For example: module bar { requires java.compiler; requires static java.base; }
Michał Szewczyk
  • 7,540
  • 8
  • 35
  • 47
26
votes
2 answers

SunPKCS11 provider in Java 9

Up to Java 8 the SunPKCS11 provider was loaded like this: Provider provider = new sun.security.pkcs11.SunPKCS11 (new ByteArrayInputStream (configFile.getBytes ())); Security.addProvider (provider); configFile is a String with the configuration…
Pepe Gutiérrez
  • 305
  • 1
  • 3
  • 6
26
votes
2 answers

Is it possible to load and unload jdk and custom modules dynamically in Java 9?

I am beginner in JPMS and can't understand its dynamism. For example, in current JVM instance moduleA.jar is running. moduleA requires only java.base module. Now, I want to load dynamically moduleB.jar that needs java.sql module and…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
25
votes
4 answers

Meaning of lambda () -> { } in Java

I am looking at the following Stack Overflow answer: How to change Spring's @Scheduled fixedDelay at runtime And in the code there is the following line: schedulerFuture = taskScheduler.schedule(() -> { }, this); I would like to know what the…
Aliuk
  • 1,249
  • 2
  • 17
  • 32