Take a look at the Java 6 Compiler API
views:
227answers:
3If you want to actually compile code from within java, it's doable but not trivial.
It's much better to use a scripting framework like Groovy--that would work great. Groovy is very java-compatible, it will almost always run java code directly (there are a few strange exceptions)
BeanShell is another scripting framework.
These both do just what you want without the effort of trying to figure out how to compile a class then load it into your existing runtime. (Actually, the problem I've seen isn't the initial compile, it's flushing your class so you can replace it with a new one after an edit).
what i have done till now:-
//JTextArea = CustomCodeImageText String Code=CustomCodeImageText.getText();
try{ FileWriter outFile = new FileWriter(TempOpeartionFile);Code=Code.replaceAll("\n",""); Code=Code.replaceAll("\t",""); File TempOpeartionFile=new File("CustomMethodClass.java");
PrintWriter out = new PrintWriter(outFile); out.println("import java.awt.*;"); out.println("import javax.swing.*;"); out.println("import javax.imageio.*;"); out.println("import java.awt.image.*;"); out.println("import java.awt.image.ColorModel;"); out.println("class CustomMethodClass {"); out.println(Code); out.println("}"); out.close(); }catch(IOException e){} String[] command = new String[4]; command[0] = "cmd"; command[1] = "/C"; command[2] = "javac "; command[3] = "CustomMethodClass.java"; Process process = Runtime.getRuntime().exec(command); custom=new CustomMethodClass(); BufferedImage manipulated=custom.customOperation(currentImage);
but,i m getting manipulated image only once i.e on clicking apply button first time.
but after doing some modifications in code inside JTextArea i m getting the same old manipulated Image rather than the newer one.