1
JAR에서 메소드를 실행하려면 메소드는 public static SomeType getValue()
처럼 보일 것입니다. JAR 파일의 클래스에서 값 가져 오기
targetType value = targetClass.cast(getValueMethod.invoke(null));
value
의 유형 targetType
수 없습니다되지 않습니다
URLClassLoader classLoader = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}, Main.class.getClassLoader());
Class targetClass = classLoader.loadClass("some.package.TargetClass");
Class targetType = classLoader.loadClass("some.package.SomeType");
Method getValueMethod = targetClass.getMethod("getValue");
그러나 잠시
이 같은 반환 값을 얻기? 그러나 내가 제대로getValue()
의 가치를 얻을 및 데이터에 액세스 할 수있는 방법, 유형
SomeType
는 JAR 파일에, 그래서,
SomeType value = ~~
다음
처럼 할 수 없어?
리플렉션도 사용합니다. 그런데 왜 그걸하고 있니? 클래스 패스에 항아리 파일이없는 이유는 무엇입니까? 더 높은 수준에서 달성하려는 것은 무엇입니까? –
'jarFile'을 동적으로 변경할 수 있기 때문에. 하지만 classpath를 설정하는 것은 정적 인 방법입니다. – QueN