• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there any API to allow my app compile an user code and show me the log?  RSS feed

 
Rodrigo Pimenta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
This is my first time in javaranch. :-)
Nowadays, I'm doing an application to allow people edit end compile java code.
So, my app has a JTextArea, where java code should be written. In addiction, my app has another JTextArea, where it should show the log of compiling the written code. Then, I need know how can my app use the written code, analize it (sintaxe check, for example) and show me the result of compiling the code. That is, what must I do to deal with the written code and analize it?
Is there any API appropriate to deal with the java code, into my app, in such way? If yes, what is its name?
Is it possible to analize the code, into my app (sintaxe check) without putting it into a file?
Any hint will be very helpful.
Thanks
Rodrigo
Brazil.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use java.lang.Runtime.exec() to execute javac on a temporary file and get the output from the java.lang.Process object. That would probably be easiest. I think you can also invoke the main() method of the java compiler (what runs when you call javac), but I can't offhand remember what the class name is.
 
Rodrigo Pimenta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
You could use java.lang.Runtime.exec() to execute javac on a temporary file and get the output from the java.lang.Process object. That would probably be easiest. I think you can also invoke the main() method of the java compiler (what runs when you call javac), but I can't offhand remember what the class name is.

Hi Joe,
Thank you. It is correct.
But, how could I get the output by menas of Processor object?
I have just coded:
process.getOutputStream()
But, what should I do with the return of comand above?
Thanks again.
Rodrigo.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with Java I/O? There's a section in the Java Tutorial that deals with it.
 
Rodrigo Pimenta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
Are you familiar with Java I/O? There's a section in the Java Tutorial that deals with it.

Ok.
Thanks.
I'm going to take a look on that.
Hugs.
Rodrigo.
 
Pedro Martello
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rodrigo Pimenta:

Ok.
Thanks.
I'm going to take a look on that.
Hugs.
Rodrigo.


Rodrigo,
did you ever get an answer to this. Essentially you need to construct a ByteArrayOutputStream using the process.getOutputStream() return value as the constructor parameter. You can then "read" the output using one of the methods in the resulting object.
Alternatively, you can also use the OutputStreamWriter to convert your stream from the 8bit to 16bit characters.
Pedro
PS: Did you go to St. Paul's School in Brazil?
 
Rodrigo Pimenta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Thank you.
No, I got my graduation in another school, in Brazil
Have you ever come to Brazil any time?
Hugs,
Rodrigo.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!