-1

I have a jtextarea, and all I want to do is be able to write some code in it (in java) and be able to execute said text as a program

  • save the code in a .java file, compile it with cmd and then execute it via cmd – XtremeBaumer Feb 10 '17 at 15:07
  • @XtremeBaumer you mean to save the code into a .java file. javac processes .java files into .class files – ControlAltDel Feb 10 '17 at 15:09
  • Try checkout this suggestion : http://stackoverflow.com/a/29709521/1959181 ; you should save the code file using the template in this link and then call this code: `Runtime.getRuntime().exec("YourFile.java")` , but it depends on your machine environment. – Edgard Leal Feb 10 '17 at 16:06
  • Possible duplicate of [Java compiler at Runtime](http://stackoverflow.com/questions/3537427/java-compiler-at-runtime) – Alessandro Da Rugna Feb 10 '17 at 16:13
  • see this answer: http://stackoverflow.com/questions/17790198/how-to-run-groovy-script-in-java – anders Feb 10 '17 at 16:13

1 Answers1

0

What language do you intend to write/run? If it's javascript, this can be accomplished using ScriptEngine. If it is Java, you'll need to save the code into a file, use javac to generate a .class file, and then use URLClassLoader to load it into your process.

Other languages are going to have other steps, obviously

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80