• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile From Java  RSS feed

 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Len Padson
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!