在 Java 小程序中包含 Javac
我不想创建一个包含 Java 编译器并且能够从网络(或从文本字段)下载和编译 .java 文件的小程序。 据我了解,Java编译器是基于Java的,所以这应该是可能的。 然而,我想知道的一件事是 Java 编译器是否能够将类文件存储在内存中,或者它需要显式的磁盘访问。 另外,我想捕获 javac 产生的错误,但这是很自然的。
也许某处有关于此的文章吗?我找不到太多关于这个案子的信息。我可能会遇到什么麻烦?
编辑:我计划将小程序与 OpenCL 一起使用,因此我必须对该小程序进行签名。
编辑:类似的问题在这里:托管Java编译器在小程序中还是在 Google AppEngine 中?
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 class 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java编译器一直在你身边。您应该使用 java.lang.Compiler 类。但我相信您会遇到 SecurityManager 的问题。
如果我是你,我更愿意在服务器端编译代码。这意味着我将开发能够获取 java 源代码并编译它的 servlet。生成的 java 类应该可以通过 HTTP 在配置为可由小程序访问的路径下使用,因此您的小程序将能够在编译后运行此类。
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.
来自 SSCCE 基于文本的编译器的文档:
From the documentation on the SSCCE Text Based Compiler: