build: 兼容jdk版本的加载jar
This commit is contained in:
parent
12a915cda1
commit
76ad13e7d0
|
@ -13,7 +13,7 @@ ENV JAVA_CLASSPATH=/opt:/opt/lib/ms-jmeter-core.jar:/opt/lib/*
|
||||||
ENV JAVA_MAIN_CLASS=io.metersphere.Application
|
ENV JAVA_MAIN_CLASS=io.metersphere.Application
|
||||||
ENV AB_OFF=true
|
ENV AB_OFF=true
|
||||||
ENV MS_VERSION=${MS_VERSION}
|
ENV MS_VERSION=${MS_VERSION}
|
||||||
ENV JAVA_OPTIONS="-Dfile.encoding=utf-8 -Djava.awt.headless=true"
|
ENV JAVA_OPTIONS="-Dfile.encoding=utf-8 -Djava.awt.headless=true --add-opens java.base/jdk.internal.loader=ALL-UNNAMED"
|
||||||
|
|
||||||
RUN mv /opt/lib/ms-jmeter-core*.jar /opt/lib/ms-jmeter-core.jar
|
RUN mv /opt/lib/ms-jmeter-core*.jar /opt/lib/ms-jmeter-core.jar
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -110,24 +109,18 @@ public class PluginService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJar(String jarPath) {
|
private void loadJar(String jarPath) {
|
||||||
File jarFile = new File(jarPath);
|
|
||||||
// 从URLClassLoader类中获取类所在文件夹的方法,jar也可以认为是一个文件夹
|
|
||||||
Method method = null;
|
|
||||||
try {
|
try {
|
||||||
method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||||
} catch (NoSuchMethodException | SecurityException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
// 获取方法的访问权限以便写回
|
|
||||||
try {
|
try {
|
||||||
|
Method method = classLoader.getClass().getDeclaredMethod("addURL", URL.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
// 获取系统类加载器
|
method.invoke(classLoader, new File(jarPath).toURI().toURL());
|
||||||
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
} catch (NoSuchMethodException e) {
|
||||||
|
Method method = classLoader.getClass()
|
||||||
URL url = jarFile.toURI().toURL();
|
.getDeclaredMethod("appendToClassPathForInstrumentation", String.class);
|
||||||
//URLClassLoader classLoader = new URLClassLoader(new URL[]{url});
|
method.setAccessible(true);
|
||||||
|
method.invoke(classLoader, jarPath);
|
||||||
method.invoke(classLoader, url);
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue