Forums Register Login

Compile From Java

+Pie Number of slices to send: Send
Hello everybody! I know Eclipse is itself a Java application, and it obviously has a button to compile and run code. What code would I have to use to, for example, compile a file written in a JTextArea? And then what code would I need to use to run said application?
+Pie Number of slices to send: Send
You'd need the JDK to compile it, with the javac command (in a console window), and the JRE (which is included with the JDK) to run it, with the java command (also in a console window).

Start here. There are step-by-step instructions. http://docs.oracle.com/javase/tutorial/getStarted/cupojava/index.html
+Pie Number of slices to send: Send
Thank you, but I think you misinterpreted my question. I understand how to compile and run an application myself, but I would like to do it from the application. For example, I would like a JFrame to hold a JTextArea and a JButton, and the user types code into the textarea and then clicks the button to compile and run the code that the user just wrote.

I think it has something to do with this, but I am not sure how to implement it: JavaCompiler
+Pie Number of slices to send: Send
For compiling, I think most IDEs just invoke javac or ant or maven as an external process. I think Eclipse does come with its own compiler. No idea how it's implemented though, or what support is provided for it in the core API

For running, again, I would expect that the most common is for the IDE to just invoke a separate JVM, but I suppose they could maybe invoke your project's main() directly.
+Pie Number of slices to send: Send
 

Len Padson wrote:T
I think it has something to do with this, but I am not sure how to implement it: JavaCompiler


Check out http://www.accordess.com/wpblog/an-overview-of-java-compilation-api-jsr-199/ and http://www.java2s.com/Code/Java/JDK-6/CompilingfromMemory.htm
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 686 times.
Similar Threads
main(args) instead of main(String[] args)
Java compiler generate older versioned byte code?
Recommendation: IDEs and SCJP don't mix
Java 1.5 on mac
Not able to display starting jsp page index.jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:11:11.