I know you can't change the classpath in Java 9 because I read this: Add jar to classpath at runtime under java 9
I just want to list jar files and folders currently on the Classpath so that I can build a command line argument to the Java compiler.
// Construct compile command options
// According to: http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html
// The directory specified by -d is not automatically added to your
// classpath, so we'll add it manually.
String[] args = new String[] {"-d", classDir,
"-classpath", classPath,
"-encoding", "UTF-8",
srcFile};
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int ret = compiler.run(null, out, err, args);
To construct a classpath in Java 8 I casted to URLClassLoader which is illegal in Java 9:
ClassLoader myCl = SimpleJavaCompilerTest.class.getClassLoader();
URLClassLoader myUcl = (URLClassLoader) myCl;
for (URL url : myUcl.getURLs()) {
System.out.println(url.toString().replace("file:", ""));
}
This produced (GOOD) output like:
/tools/idea-IU-181.4445.78/lib/idea_rt.jar
...
/tools/idea-IU-181.4445.78/plugins/junit/lib/junit5-rt.jar
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar
...
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar
/blah/myApp/target/test-classes/
/blah/myApp/target/classes/
/home/me/.m2/repository/commons-fileupload/commons-fileupload/1.3.3/commons-fileupload-1.3.3.jar
...
/home/me/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar
I tried: Scanning classpath/modulepath in runtime in Java 9 but it produced a list of ~19,000 class files that are part of openjdk, but not the jar files or class folders from my project. Like (BAD):
java/awt/desktop/ScreenSleepListener.class
...
javax/accessibility/AccessibilityProvider.class
...
jdk/dynalink/beans/AbstractJavaLinker$1.class
...
META-INF/providers/org.graalvm.compiler.code.HexCodeFileDisassemblerProvider
...
module-info.class
...
netscape/javascript/JSException.class
...
org/graalvm/compiler/api/directives/GraalDirectives.class
...
org/ietf/jgss/ChannelBinding.class
...
org/jcp/xml/dsig/internal/SignerOutputStream.class
...
org/w3c/dom/xpath/XPathResult.class
...
org/xml/sax/AttributeList.class
...
sun/applet/AppContextCreator.class
...
sun/util/spi/CalendarProvider.class
...
I need the jar files and the class folders specific to my project (which are not in the java-9 list above). How do I get that in Java 9?