Skip to content

Commit eab964c

Browse files
committed
[MJAVADOC-603] javadoc:fix failure on JDK10: java.lang.ClassNotFoundException: java.sql.Connection
This closes #303
1 parent 0a26a7e commit eab964c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.thoughtworks.qdox.parser.ParseException;
6767
import com.thoughtworks.qdox.type.TypeResolver;
6868
import org.apache.commons.lang3.ClassUtils;
69+
import org.apache.commons.lang3.reflect.MethodUtils;
6970
import org.apache.commons.text.StringEscapeUtils;
7071
import org.apache.maven.artifact.Artifact;
7172
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -79,6 +80,7 @@
7980
import org.apache.maven.settings.Settings;
8081
import org.apache.maven.shared.invoker.MavenInvocationException;
8182
import org.codehaus.plexus.components.interactivity.InputHandler;
83+
import org.codehaus.plexus.languages.java.version.JavaVersion;
8284
import org.codehaus.plexus.util.FileUtils;
8385
import org.codehaus.plexus.util.ReaderFactory;
8486
import org.codehaus.plexus.util.StringUtils;
@@ -201,6 +203,8 @@ public abstract class AbstractFixJavadocMojo extends AbstractMojo {
201203
*/
202204
private static final String CLIRR_MAVEN_PLUGIN_GOAL = "check";
203205

206+
private static final JavaVersion JAVA_VERSION = JavaVersion.JAVA_SPECIFICATION_VERSION;
207+
204208
/**
205209
* Java Files Pattern.
206210
*/
@@ -837,7 +841,17 @@ private ClassLoader getProjectClassLoader() throws MojoExecutionException {
837841
}
838842
}
839843

840-
projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
844+
ClassLoader parent = null;
845+
if (JAVA_VERSION.isAtLeast("9")) {
846+
try {
847+
parent = (ClassLoader) MethodUtils.invokeStaticMethod(ClassLoader.class, "getPlatformClassLoader");
848+
} catch (Exception e) {
849+
throw new MojoExecutionException(
850+
"Failed to invoke ClassLoader#getPlatformClassLoader() dynamically", e);
851+
}
852+
}
853+
854+
projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
841855
}
842856

843857
return projectClassLoader;

0 commit comments

Comments
 (0)