I have the following problem with Java9 using the below simple application. The application has the main class Main:
package app;
import lib.Greeting;
public class Main {
public static void main( String[] args ) {
System.out.println( new Greeting().hello() );
}
}
The class Greeting is the following and packaged in the separate jar library lib.jar:
package lib;
public class Greeting {
public String hello() {
return "Hi from Greeting lib!";
}
}
The application Main and lib.jar are packaged by Eclipse to the app.jar library with the manifest file as follows:
**Manifest-Version: 1.0
Rsrc-Class-Path: ./ lib.jar
Class-Path: .
Rsrc-Main-Class: app.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader**
When I run this application with Java8, it works as expected:
C:\java\J9Test\libs>java -jar app.jar
Hi from Greeting lib!
When I run this application with Java9, the following exception is raised:
C:\orawork\java\J9Test\libs>d:\jdk1.9\bin\java.exe -jar app.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: lib/Greeting
at app.Main.main(Main.java:7)
... 5 more
Caused by: java.lang.ClassNotFoundException: lib.Greeting
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 6 more
How to resolve this problem and run this simple app successfully with both Java8 and 9?