2008-09-19 41 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来加载它。