Skip to content

Commit

Permalink
Alternative class loader hack for Java 9/10. For #12
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjefferson committed Feb 27, 2019
1 parent 7fafaa3 commit 7412357
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/org/datanucleus/maven/AbstractDataNucleusMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,18 @@ protected void executeInJvm(String className, List args, List cpEntries, boolean
}

ClassLoader parent = null;
/*try
try
{
parent = ClassLoader.getPlatformClassLoader();
Method method = ClassLoader.class.getMethod("getPlatformClassLoader", (Class)null);

This comment has been minimized.

Copy link
@devaraj-kavali

devaraj-kavali Mar 2, 2019

It is still failing for Java 11 with this,

java.lang.NoSuchMethodException: java.lang.ClassLoader.getPlatformClassLoader(null)
        at java.base/java.lang.Class.getMethod(Class.java:2109)

I think this needs to be changed this way to work with Java 11.

-                Method method = ClassLoader.class.getMethod("getPlatformClassLoader", (Class)null);
+                Method method = ClassLoader.class.getMethod("getPlatformClassLoader");

This comment has been minimized.

Copy link
@andyjefferson

andyjefferson Mar 2, 2019

Author Member

So are you saying you have actually checked your proposed code?
As I said in a related PR, and issue, I DO NOT USE JAVA 9+ and it is FOR OTHER PEOPLE TO CONTRIBUTE when they want such things (unwillingness to contribute means people will NOT get anything beyond what I want myself). All has to be buildable using Java 8.

Confirm that this works with Java 9+ and I can make the change.

This comment has been minimized.

Copy link
@devaraj-kavali

devaraj-kavali Mar 5, 2019

Thanks for checking this.

I verified it, the proposed code works for Java 9+ (9,10, 11).

This comment has been minimized.

Copy link
@andyjefferson

andyjefferson Mar 6, 2019

Author Member

See v5.2.1

parent = (ClassLoader)method.invoke(null);
getLog().debug("Java 9 or higher detected. Using modern classloader strategy.");
}
catch (NoSuchMethodError e)
catch (Throwable thr)
{
getLog().debug("Java 8 or older detected. Using legacy classloader strategy.");
}*/
}
URLClassLoader loader = new URLClassLoader(urls, parent);

Class c = loader.loadClass(className);
Method m = c.getMethod("main", new Class[] { String[].class });
ClassLoader tl = Thread.currentThread().getContextClassLoader();
Expand Down

0 comments on commit 7412357

Please sign in to comment.