2015-02-06 5 views
1

프로그램 용 API 시스템에서 작업 중입니다. 이 시스템은 '플러그인'폴더로 이동하여 모든 항아리를로드합니다. 'plugin'폴더에있는 jar 파일의 기본 클래스를로드하려고 시도하지만 그렇게하는 동안 ClassNotFoundException이 발생합니다. 질문이 모호하고 불분명jar 파일을로드 할 때 Java 클래스를 찾을 수 없습니다.

private static void loadClassFromJar(String PluginJar) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException { 
    logger.debug("jar:file:" + "./debug/plugins/DiamondCorePlugin.jar!/"); 
    URL[] urls = { new URL("jar:file:" + FileList.PluginFolder.getAbsolutePath() + PluginJar +"!/") }; 
    URLClassLoader ClassLoader = URLClassLoader.newInstance(urls); 
    Class<?> Class = ClassLoader.loadClass("net.trenterprises.diamondcore.plugin.Main"); 
    Object Object = Class.newInstance(); 
    Method EventMethod = Object.getClass().getMethod("onEnable"); 
    EventMethod.invoke(Object); 
} 

있으면 알려 주시기 바랍니다 (I 여기 주위에 새로운 오전, 그래서 난 내에 가장 단어를 물어 질문을보십시오) :

여기 내 코드입니다.

편집 : 스택 추적을 잊어 버렸습니다. 여기있어!

java.lang.ClassNotFoundException: net.trenterprises.diamondcore.plugin.Main 
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:798) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadClassFromJar(PluginLoader.java:53) 
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadAllPlugins(PluginLoader.java:25) 
at net.trenterprises.diamondcore.DiamondCoreServer.<init>(DiamondCoreServer.java:47) 
at net.trenterprises.diamondcore.run.main(run.java:15) 
+0

''enterprises' –

답변

1

중 하나 지퍼 도구 나 jar -tf DiamondCorePlugin.jar, 또는 항아리-URL 확인 (요청 된 클래스를 포함하지 않는 항아리가 정확하지가 (단지가 아닌 단지 자체 내부 리소스를 가리 키도록 보인다 .) 당신은 같은 좀 더 쉽게 그것을 만들 수 있습니다? 어쩌면 당신 말은, 이상한 이름처럼 보인다 trenterprises`

File file = new File("debug/plugins/DiamondCorePlugin.jar"); 
URL[] urls = { file.getAbsoluteFile().toURI().toURL() }; 
+0

이 좋아,이 작품 감사합니다.! – Whirvis