JC Leyba
JC Leyba

Reputation: 520

How to implement a built in compiler in Java/Swing?

I'm writing a text/code editing program for my own use in Java/Swing, and was wondering how I would go about setting up a built-in C compiler inside it. I would likely use GCC or TCC as the compiler. Anyway, my question is- how would I actually implement the compiler? Would I use a library that gives Java access to command line commands? Are there such libraries and if so, which is the best/easiest to use?

Thanks.

Upvotes: 0

Views: 286

Answers (2)

Teja Kantamneni
Teja Kantamneni

Reputation: 17482

Typically IDE/Editor's don't implement the compilers. They will just execute the commands and pass the filename as argument (along with other necessary files). They also pipe/stream the output to a separate window/pane in the editor. So you need to integrate the compiler somehow not implement one. You can execute the commands in java using Runtime class. Start here.

Upvotes: 2

Klark
Klark

Reputation: 8280

Accessing command line is the easiest way. Try something like this:

Process myProc = Runtime.getRuntime().exec(command);

Where command is some string you want to pass to the command line.

After that you can redirect output / input of that process to the some java buffers to have the full control.

myProc.getInputStream();
myProc.getOutputStream();

Upvotes: 2

Related Questions