public static void execute(String[] dataArray)throws Exception {
        // 加载 JAR 文件 路径
        URL jarUrl = new URL("file:/D:/xx/xx/xxx.jar");

        URLClassLoader classLoader = new URLClassLoader(new URL[]{jarUrl});

        // 加载 JAR 文件中的类和方法
        Class<?> jarClass = classLoader.loadClass("com.xx.xx.xxx"); // 替换为实际的类名
        Method method = jarClass.getMethod("start", String[].class); // 替换为实际的方法名和参数类型

        // 调用方法
        Object instance = jarClass.getDeclaredConstructor().newInstance();
        method.invoke(instance, (Object) dataArray);

        // 关闭类加载器
        classLoader.close();
    }

另一边方法如下:

    public static  void start(String[] args)throws Exception{}

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐