How can I get *.classes generated by the correct *.java files when I use javac command to compile many dependent *.java files with a few errors?

Viewed 282

When I use javac to compile many independent .java file, I find if one fails, no .class file will generate. For example, I try this command:

javac A.java B.java C.java -Xmaxerrs 200 -Xmaxwarns 200

There are no dependencies among these *.java files. When I use the command above to compile these *.java files, I find:
Case 1: All of the *.java files are correct. I will get A.class, B.class and C.class after javac's compilation.
Case 2: A.java has some errors, B.java and C.java are both correct. After compilation, I can't get any .class file.

How can I get B.class and C.class after javac's compilation in Case 2? Is there any javac option to solve this problem?

4 Answers

As there are no dependencies among the source code files, the simplest solution I can think of is to invoke javac once for each source file.


As an alternative you can use ECJ, the compiler used by the Eclipse IDE and part of JDT Core. From the linked page:

In particular, it allows to run and debug code which still contains unresolved errors.

This is one of the main differences between javac and the Eclipse compiler.

It is available as a separate download (see section JDT Core Batch Compiler for any build linked from the download page). There are help pages describing how to use the compiler programmatically or as a separate application from the command line.

Related