Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Tags:

java

javac

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?

like image 396
jimmyzhao Avatar asked Feb 25 '26 08:02

jimmyzhao


2 Answers

Remove A.java and check the output if it work then check the error of A.java and recompile

After removing a.java compiler not work then try to debugging main java codes.

like image 133
Sanjeev Chauhan Avatar answered Feb 27 '26 20:02

Sanjeev Chauhan


Workaround: IDEs such as Eclipse or IntelliJ compile "as much as possible". They even allow you to run code that doesn't completely compile!

Alternatively, you could look into using a build system such as maven, gradle, ... - such tools will for sure allow for this.

( and for any project of reasonable size, using a build system is "mandatory" anyways - because of that: directly using javac manually is just a pain, and makes things that should be easy to do pretty complicated sometimes )

like image 43
GhostCat Avatar answered Feb 27 '26 21:02

GhostCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!