외부 .jar 파일에서 클래스를 가져 오는 데 문제가 있습니다. 여기 외부 .jar를로드하는 방법은 this이지만, 실행할 때마다 ClassNotFoundException이 발생합니다. 아래 코드는 내가 사용하고있는 코드이며 here은 내가 테스트 할 .jar입니다. 누구든지이 문제를 해결하는 방법에 대해 알고 있다면 나에게 말해주십시오. 감사!Java : 외부 .jar에서 클래스 가져 오기
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public void loadJar() throws MalformedURLException {
URL[] classes = {new URL("jar:file://test.jar!/")};
URLClassLoader child = new URLClassLoader (classes, this.getClass().getClassLoader());
try {
Class classToLoad = Class.forName ("test.PackageTest", true, child);
Method method = classToLoad.getDeclaredMethod ("test");
Object instance = classToLoad.newInstance();
Object result = method.invoke(instance);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
이 부분은 무엇인가요? http://stackoverflow.com/questions/9880385/java-build-path –