How can I get * .class generated by correct * .java files when I use javac command to compile many dependent * .java files with multiple errors?
When I use javac to compile many independent .java files, I find that if one of them doesn't work, the .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 between these * .java files . When I use the command above to compile these * .java files I find:
Case 1 . All * .java files are correct. After javac compilation I will get A.class, B.class and C.class.
Case 2 : A.java has some bugs, B.java and C.java are both correct. After compiling, I cannot get the .class file.
How can I get B.class and C.class after javac compilation in Case 2 ? Is there any javac option to solve this problem?
source to share
Workaround: IDEs like Eclipse or IntelliJ compile "as much as possible". They even let you run code that doesn't fully compile!
Alternatively, you can look into a build system like maven, gradle, ... - such tools will surely allow you to do this.
(and for any reasonably sized project, using the build system is "mandatory" anyway - because of this: using javac directly by hand is just painful and makes things that should be easy to do quite difficult sometimes)
source to share
Since there are no dependencies between the source files, the simplest solution I can think of is to call javac
once for each source file.
Alternatively, you can use ECJ, the compiler used by the Eclipse IDE and part of the JDT Core . From the linked page:
In particular, it allows you to run and debug code that 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 the JDT Core Batch Compiler section for any assembly linked to the download page ). There are man pages that describe using the compiler programmatically or as a standalone application from the command line .
source to share