If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Compiling And Running

Hi everyone,

I am trying to compile some java codes from a .java file that i had saved to disk. Basically i am trying to build my own ide. I have a text area in which the java code is in and also have two buttons. What i need is when i click the button the .java file on my disk is compiled and any errors are shown in the textarea

For the second button when i click it(if compilation is successfull) for the .java that has been compiled to be run.

Does anyone know how to compile and run a java program from a program?

I hope someone can help or show me some codings on how this can be achieved.

Your method worked as expected once I fixed a couple of compile errors...

I can't try exactly what you are doing, because I'm typing on an iMac right now. However, I did modify str9 to be "/bin/echo" and str10 to be "Hello World!", and as expected, the output file containted "Hello World!" after running.

So, with that in mind, make sure the path to javac is correct(with correct path separator characters). Those strings are incorrect in what you posted. See comments in the code below.

Here is the code (after I changed it to a main() method that I could run):

There is no exception thrown but the exit value of the process is 1 (meaning the program exited abnormally). I do not know what i am doing wrong. Am i running the compiled class the correct way. If not then what is the correct way of doing it. The program i trying to run has no errors when compiled. Basically what i need is a way to change my class path programatically.

I already did that but the compiled class is not run but the program exits abnormally and there are no exceptions. I am thinking it has something to do with the classpath but i am not sure if i am setting it correctly in the above code snippet. I also tried this( as an attempt to change the classpath)

What i think is that the problem has to do with the setting of my arguments in the str12 array and i maybe my setting of the class path is wrong but i am very sure of setting the classpath correctly
programatically