The following code (to retrieve the base URL of a Java Web Start client application via the JNLP API) worked in Java 8 but failed when executed in (modularized) Java 9 runtime:
Class<?> mclass = Class.forName("javax.jnlp.ServiceManager");
Method lookup = mclass.getMethod("lookup", new Class[]{String.class});
Object basicSvc = lookup.invoke(null, new Object[{"javax.jnlp.BasicService"});
Class<?> sclass = basicSvc.getClass();
Method getCodeBase = sclass.getMethod("getCodeBase", (Class[])null);
URL codebase = (URL)getCodeBase.invoke(basicSvc, (Object[])null); // throws
Results in
java.lang.IllegalAccessException: class app.App cannot access class
com.sun.jnlp.BasicServiceImpl (in module jdk.javaws) because module
jdk.javaws does not export com.sun.jnlp to unnamed module @7202a0fa
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException
at java.base/java.lang.reflect.AccessibleObject.checkAccess
at java.base/java.lang.reflect.Method.invoke
at app.App.init
How can this be fixed?