3
에서 호출되는 읽기 (jar1하고 말할 수 있습니다 jar2). jar2에는 하나의 xml 파일이 있습니다. 나는 xml 파일을 읽고 싶다. 내가 나는 두 개의 jar 파일이 항아리 내부에 존재하는 파일이 다른 jar 파일
public void readXmlFile(){
InputStream resourceAsStream = MainFile.class.getResourceAsStream("/test.xml");
}
을 사용하지만 지금은
File file = new File(jar2);
URL url = file.toURL();
URL[] urls = new URL[] { url };
ClassLoader cl = new URLClassLoader(urls);
Class<?> compositeClass = cl.loadClass(XmlFileReader);
Method declaredMethod = compositeClass.getDeclaredMethod("readXmlFile");
Object newInstance = compositeClass.newInstance();
declaredMethod.invoke(newInstance);
XML 파일이 jar1과하지 jar2에서 검색되는대로 지금은 FileNotFoundException이 무엇입니까, 내가 사용 jar1의 클래스 FRM이 함수를 호출하고 왜 이런 일이 일어나는 지 모르겠다. 누구든지 나를 도울 수 있습니까?
및하여 jar2처럼 내되는 ReadXml 방법을 수정 jar1에서 호출되는 것은 따라서, CL 파일이 jar1에보고하지 jar2..please 도움 – Ankit
에되고 그래서 jar1의 classlaoder는 당신이'compositeClass = Class.forName을 ("fqcn.XmlFileReader"를 시도 않았다 사용되는 수 있습니다)' – shyam
또한 당신은 시도해 볼 수도 있습니다'file.getAbsoluteFile(). toURL()'당신은 "부트 스트랩"클래스 로더있을 때까지 당신은의 getParent()와 부모 클래스 로더를 얻을 수 – shyam