Accessing resource files from external modules

// to scan the module path ClassLoader.getSystemResources(resourceName) // if you know a class where the resource is Class.forName(className).getResourceAsStream(resourceName) // if you know the module containing the resource ModuleLayer.boot().findModule(moduleName).getResourceAsStream(resourceName) See a working example below. Given: . ├── FrameworkCore │ └── src │ └── FrameworkCore │ ├── com │ │ └── framework │ │ └── Main.java │ … Read more

Tomcat 7.0.73 doesn’t work with java 9

You’ll have to hack the script bin/catalina.sh to get this to work. There are a bunch of lines like this in bin/catalina.sh: exec “$_RUNJDB” “$LOGGING_CONFIG” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS” -classpath “$CLASSPATH” \ … Just remove the second of those lines (the one with -Djava.endorsed.dirs) in each case and you should be back in business. … Read more

How to access resource using class loader in Java 9

From ClassLoader.getResource JavaDoc: Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with “.class”, this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this … Read more

Add jar to classpath at runtime under java 9

The JavaSE9 release notes read about the same : The application class loader is no longer an instance of java.net.URLClassLoader (an implementation detail that was never specified in previous releases). Code that assumes that ClassLoader::getSytemClassLoader returns a URLClassLoader object will need to be updated. Note that Java SE and the JDK do not provide an … Read more

–add-modules only on compilation [duplicate]

I made this answer a while ago where I answered this as an additional info to exposing non java.se packages in Java-9 using Maven. The added part specifically focusses on using the standalone version of the java.xml.* APIs. To adapt to which you can probably start consuming the dependency on jaxb-api:2.3.0 which can be loaded … Read more

Is there a way to add maven dependencies while using the maven-jlink-plugin?

This has not much to do with the plugin I believe. Module joda.time in your case seems to be an automatic module. The jlink tool does not support linking of automatic modules because they can rely on the arbitrary content of the classpath, which goes against the idea of a self-contained Java runtime. So there … Read more

Neon: how to run on jdk9?

Edit: You can download the latest version of eclipse which has support for Java 9 – https://www.eclipse.org/downloads/eclipse-packages/ I am running Java(TM) SE Runtime Environment (build 9-ea+158) and eclipse Version: Neon.2 Release (4.6.2) – Build id: 20161208-0600 Somehow the solutions with -Djdk.launcher.addmods= and -addmods using values java.se.ee or java.annotations.common did not work. Below is the solution … Read more

Observer is deprecated in Java 9. What should we use instead of it?

Why is that? Does it mean that we shouldn’t implement observer pattern anymore? Answering the latter part first – YES, it does mean you shouldn’t implement Observer and Obervables anymore. Why were they deprecated – They didn’t provide a rich enough event model for applications. For example, they could support only the notion that something … Read more

Java 9, compatability issue with ClassLoader.getSystemClassLoader

You’ve run into the fact that the system class loader is no longer a URLClassLoader. As indicated by ClassLoader::getSystemClassLoader‘s return type, this was an implementation detail, albeit one that a non-negligible amount of code relied upon. Judging by the comments, you are looking for a way to dynamically load classes at run time. As Alan … Read more