javaappletjavac

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 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?


Solution

  • 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.