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?

+3


source to share


4 answers


Remove A.java and check the output if it works, then check the A.java error and recompile



After uninstalling the compiler a.java doesn't work, try debugging basic java codes.

+2


source


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)

+1


source


If there are dependencies from A to B or C, and class A has some compilation problem, then classes B.class and C.class will not be generated either. Fix compilation problem in or clean dependencies.

0


source


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 .

0


source







All Articles