Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Compile From Java

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic