Skip to main content

How do i get the output of java compiler error messages?

2 replies [Last post]
hoyroy
Offline
Joined: 2008-07-11
Points: 0

i am doing a simple application that will collect java compile errors and store these error in a database. i chose bluej (www.bluej.com) it shows one compilation at a time. i think this will be much more convenient for me. can you make a suggestion on how can i be able to do this? your help will be much appreciated. thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shagus
Offline
Joined: 2007-05-10
Points: 0

Hi, this is not directly related to JavaFx, but here is the example that will collect java compiler
errors and store the errors in a file.
The TestCompiler.java compiles Foo.java and the compiler output of Foo.java is written to out.txt.

Running this example:

javac TestCompiler.java
java TestCompiler

//TestCompiler.java
import java.io.*;
import javax.tools.*;

public class TestCompiler {
public static void main( String args[]) throws IOException {
Tool compiler = ToolProvider.getSystemJavaCompiler();
OutputStream out = new FileOutputStream("out.txt");
int results = compiler.run(null, null, out, "Foo.java");
System.out.println("Success: " + (results == 0));

}

}

//Foo.java
public class Foo {
public static void main( String args[]) {
System.out.println("Hello World");

}

}

hoyroy
Offline
Joined: 2008-07-11
Points: 0

Thank you very much for the nice input!! it really helped us a lot!!
god bless!