开发者

Include Javac in Java applet

I wan't to create an applet that includes the Java compiler and is able to download and compile .java files from the web (or from a textfield for that matter). From what I understand, the Java compiler is based on Java, so this should be possible. However, one thing I wonder is wether the Java compiler is able to store the clas开发者_如何学JAVAs file in memory or that it needs explicit disk access. Also, I want to catch the errors javac produces, but this is natural.

Is there an article on this somewhere maybe? I couldn't find much on the case. What troubles could I walk into?

EDIT: I'm planning on using the applet with OpenCL, so I would have to sign the applet.

EDIT: Similar question here: Hosting the Java compiler in an applet or in Google AppEngine?


Java compiler is always with you. You should use java.lang.Compiler class. But I believe you will have issues with SecurityManager.

If I were you I'd prefer to compile code on server side. It means that I'd develop servlet that is able to get the java source and compile it. The resulted java class should be available over HTTP under path that is configured to be accessible by applet, so your applet will be able to run this class after compilation.


From the documentation on the SSCCE Text Based Compiler:

  • javax.tools.ToolProvider. The docs for getSystemJavaCompiler() mention that it returns "the compiler provided with this platform or null if no compiler is provided", but do not make clear why it might be null, nor the fact that the compiler will not be available to applets or webstart apps.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜