1

一开始,它一切正常,然后它就停止了,我真的不知道我是否对它做了什么,或者其他地方有问题。

我的类加载器应该在运行时加载一个 jar 文件,但显然它没有。

String url   = "https://" + serverHost + "/" + getJarPath() + "se.jar";
log.info("http url is: " +url);
String https = url.replaceAll("\\s","");

URL httpsURL = new URL(https);  
log.info("https url is: " + httpsURL);

URLConnection con = httpsURL.openConnection();              
addURL(con.getURL());



private void addURL(URL https) throws IOException { 
        Class<?>[] parameters = new Class[]{URL.class}; 
        // IMPORTANT: MUST use the webapp classloader - so derived extension classes can resolve their base classes
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();        
        // cast to a URL class loader so we can add additional JAR(s) to the search path
        URLClassLoader webappClassLoader = (URLClassLoader)contextClassLoader;  
        Class<?> sysclass = URLClassLoader.class;

        Method method;
        try {
            method = sysclass.getDeclaredMethod("addURL", parameters);
            method.setAccessible(true);
            method.invoke(webappClassLoader, new Object[]{ https });
        } catch (NoSuchMethodException | SecurityException e) {
            log.log(Level.WARNING, "FATAL Exception", e);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            log.log(Level.WARNING, "FATAL Exception", e);
        }
    }

我不能透露 URL 的完整路径,但我可以确认 101% jar 是字符串 url 所说的位置,但我确实得到了 DefNotFoundClassException。

4

0 回答 0