2
현재 활성 파일을 실행하는 Eclipse 플러그인을 개발 중입니다. 나는이 방법플러그인 설치시 동적 실행이 작동하지 않습니다.
public static void runIt(String fileToCompile,String packageName) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException, SecurityException, NoSuchMethodException
{
File file = new File(fileToCompile);
try
{
// Convert File to a URL
URL url = file.toURL(); // file:/classes/demo
URL[] urls = new URL[] { url };
// Create a new class loader with the directory
ClassLoader loader = new URLClassLoader(urls);
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
Class<?> thisClass = classLoader.loadClass("NewFile");
Object newClassAInstance = thisClass.newInstance();
Class params[] = new Class[1];
params[0]=String[].class;
Object paramsObj[] = {};
String m=null;
Object instance = thisClass.newInstance();
Method thisMethod = thisClass.getDeclaredMethod("main", params);
String methodParameter = "a quick brown fox";
// run the testAdd() method on the instance:
System.out.println((String)thisMethod.invoke(instance,(Object)m));
}
catch (MalformedURLException e)
{
}
}
을 사용하고하지만 "시작 이클립스 응용 프로그램"[다른 이클립스 창에서 플러그인 실행]을 때 작동하지만 이클립스의 플러그인을 설치할 때 그것은 더 이상 작동하지 않습니다. 문제는이 줄에 있습니다.
클래스 thisClass = classLoader.loadClass ("NewFile"); 실행할 클래스를 찾을 수 없습니다.
'packageName'은 무엇을 의미 않습니다
당신이
? –URLClassLoader
(코드에서 포기 된 것으로 나타나는), 당신처럼, 그것을 부모를 줄 필요가 사용할 경우