2008-09-19 54 views
1

我在我的客戶端應用程序中動態編譯代碼。當我用Java Web Start啓動應用程序時,我得到一個異常。只有通過Java Web Start運行時纔會發生異常。如何在動態編譯代碼時訪問由Java Web Start加載的類?

//The exception 
evolver.core.model.change.execution.ExecutionException: Compilation failed! 

DynamicComparator.java:2: package evolver.core.model.i does not exist 
import evolver.core.model.i.IDefaultObject; 
         ^
DynamicComparator.java:9: cannot find symbol 
symbol : class PropertyBag 
location: class DynamicComparator 
PropertyBag b2 = new PropertyBag(dob2); 
        ^

以上的PropertyBag應當提供由JNLPClassloader作爲 它是由JWS

引起該問題看起來像這樣的代碼下載的文件的一個組成部分。

public static int compile(String javaFileName) {  
    ByteArrayOutputStream os = new ByteArrayOutputStream(); 
    PrintWriter w = new PrintWriter(os); 
    int res = com.sun.tools.javac.Main.compile(new String[]{"-d", "./", javaFileName}, w); 
    if (res != 0) 
     throw new ExecutionException("Compilation failed!" + "\n\n" + os.toString()); 
    return res; 
} 

任何幫助將非常感激!

回答

1

就目前而言,您必須編譯服務器上的代碼。服務器不應該提供任何可能導致跨站點攻擊的代碼,所以要非常小心。客戶端然後可以使用URLClassLoader.newInstance來加載它。