diff --git a/.github/workflows/docker-image-tomcat.yml b/.github/workflows/docker-image-tomcat.yml deleted file mode 100644 index 25026ef8..00000000 --- a/.github/workflows/docker-image-tomcat.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Docker Image CI - Tomcat(DEPRECATED) - -on: - workflow_dispatch: - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: registry.cn-hangzhou.aliyuncs.com - username: ${{ secrets.ALI_HUB_USERNAME }} - password: ${{ secrets.ALI_HUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile-Tomcat - platforms: linux/amd64,linux/arm64 - push: true - cache-from: type=gha - cache-to: type=gha,mode=max - tags: | - ${{ secrets.DOCKERHUB_USERNAME }}/arex-replay-schedule:${{ vars.AREX_VER }}-tomcat - registry.cn-hangzhou.aliyuncs.com/${{ secrets.DOCKERHUB_USERNAME }}/arex-replay-schedule:${{ vars.AREX_VER }}-tomcat \ No newline at end of file diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/beans/ReplaySenderConfiguration.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/beans/ReplaySenderConfiguration.java index 0c8ae153..b97651c4 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/beans/ReplaySenderConfiguration.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/beans/ReplaySenderConfiguration.java @@ -1,6 +1,7 @@ package com.arextest.schedule.beans; -import com.arextest.schedule.common.ClassLoaderUtils; +import com.arextest.common.model.classloader.RemoteJarClassLoader; +import com.arextest.common.utils.RemoteJarLoaderUtils; import com.arextest.schedule.extension.invoker.ReplayExtensionInvoker; import com.arextest.schedule.sender.ReplaySender; import com.arextest.schedule.sender.ReplaySenderFactory; @@ -13,7 +14,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.ServiceLoader; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; @@ -52,8 +52,8 @@ public List invokers() { } else { classPathResource = loadLocalInvokerJar(); } - ClassLoaderUtils.loadJar(classPathResource); - ServiceLoader.load(ReplayExtensionInvoker.class).forEach(invokers::add); + RemoteJarClassLoader loader = RemoteJarLoaderUtils.loadJar(classPathResource.getPath()); + invokers.addAll(RemoteJarLoaderUtils.loadService(ReplayExtensionInvoker.class, loader)); } catch (Throwable t) { LOGGER.error("Load invoker jar failed, application startup blocked", t); } diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/ClassLoaderUtils.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/ClassLoaderUtils.java deleted file mode 100644 index b103b50a..00000000 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/ClassLoaderUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.arextest.schedule.common; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class ClassLoaderUtils { - - public static final String JDK_INTER_APP_CLASSLOADER = "jdk.internal.loader.ClassLoaders$AppClassLoader"; - - public static void loadJar(String jarPath) { - File jarFile = new File(jarPath); - if (!jarFile.exists()) { - LOGGER.error("JarFile doesn't exist! path:{}", jarPath); - return; - } - try { - loadJar(jarFile.toURI().toURL()); - } catch (Exception e) { - LOGGER.error("Load jar failed! path:{}", jarPath, e); - } - } - - public static void loadJar(URL jarUrl) { - try { - int javaVersion = getJavaVersion(); - ClassLoader classLoader = ClassLoaderUtils.class.getClassLoader(); - Method addURL = Class.forName("java.net.URLClassLoader") - .getDeclaredMethod("addURL", URL.class); - addURL.setAccessible(true); - - if (javaVersion <= 8) { - if (classLoader instanceof URLClassLoader) { - addURL.invoke(classLoader, jarUrl); - } - } else if (javaVersion < 11) { - /* - * Due to Java 8 vs java 9+ incompatibility issues - * See https://stackoverflow.com/questions/46694600/java-9-compatability-issue-with-classloader-getsystemclassloader/51584718 - */ - ClassLoader urlClassLoader = ClassLoader.getSystemClassLoader(); - if (!(urlClassLoader instanceof URLClassLoader)) { - urlClassLoader = new URLClassLoader(new URL[]{jarUrl}, urlClassLoader); - } - addURL.invoke(urlClassLoader, jarUrl); - } else if (JDK_INTER_APP_CLASSLOADER.equalsIgnoreCase(classLoader.getClass().getName())) { - /** - * append jar jdk.internal.loader.ClassLoaders.AppClassLoader - * if java >= 11 need add jvm option:--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED - */ - Method classPathMethod = classLoader.getClass() - .getDeclaredMethod("appendToClassPathForInstrumentation", String.class); - classPathMethod.setAccessible(true); - classPathMethod.invoke(classLoader, jarUrl.getPath()); - } - } catch (Exception e) { - LOGGER.error("loadJar failed, message:{}", e.getMessage()); - } - } - - private static int getJavaVersion() { - String version = System.getProperty("java.version"); - if (version.startsWith("1.")) { - version = version.substring(2, 3); - } else { - int dot = version.indexOf("."); - if (dot != -1) { - version = version.substring(0, dot); - } - } - return Integer.parseInt(version); - } -}