Ignoring Compilation Errors - Java

I have about 1,500 files to compile in which 15-20 files have compilation errors. These files are not under my control, so I could not make any changes / updates / deletes. So, I have two questions.

1) how do I ignore compilation errors from these 15-20 files and continue to create a .class file for the rest of them. is there any javac command line option or anything that will ignore addition errors and create .class files for all other files without errors.

2) the java compiler will stop compiling as soon as he sees these errors, or continue compiling (creating .class files) everything else at the end, and then complain about these files with errors.

+8
java command ignore
source share
7 answers

You can use Eclipse . Its internal compiler - at least in some cases - is able to continue working with the rest of the assembly, even if some classes are not fully compiled. It even creates class files for broken classes, if possible, by generating methods that throw an exception as soon as they are called.

I would strongly recommend that you simply take a copy of the entire source and fix the errors, at least in your own copy as early as possible, but a partial compilation of Eclipse can help you.

+12
source share

You cannot ignore compilation errors. They will always fail to build.

Your only choice is to talk to someone who controls the files to commit them or find a way to replace them.

If you try to remove them from the assembly, you will also have to delete the files that use these files. for example

class A { B b; } 

If B has a compilation error, your build script may skip B.java, but when you press A.java, it will try to compile B anyway, so A needs to be deleted. This can be a nontrivial task.

+3
source share

You can write a script that traverses your source tree and calls javac for each java file separately. Thus, you will receive all files compiled correctly that are not dependent on files with errors. However, it will be a terribly slow operation. I would expect it to take several 100 times longer than a single javac call (given that you will have about 1,500 calls).

+2
source share

You can exclude some source files from compilation using the exclude tag in the ant task.

  <target name="compile" description="Compile Java source files"> <javac destdir="classes" classpathref="classpath"> <src path="src"/> <exclude name="**/excluded_folder/**"/> </javac> </target> 

EDIT: But, of course, any java files that depend on excluded classes will also not compile unless you already have a precompiled version of the excluded files in the classpath.

+1
source share

Create layouts for corrupted files. Basically the same idea as the C header file includes function signatures and reasonable default return values ​​( null , false , 0 ). This will allow javac to compile everything, just make sure that the mock classes are not included in the final distribution, or you will get strange errors when they get to the class path first. This works to implement broken interfaces and inherit from broken classes too.

+1
source share

What means

which will ignore addition errors and create .class files for all other files without errors.

Do you understand that if these files are linked (as in one project), then the dependent source files will not compile either.? You cannot get around this except to fix compilation errors and try again!

-one
source share
  • Tell who broke the code (diplomatically, of course) to fix it as soon as possible. Others suggested (see 2nd comment) to make these events publicly available (within the team / company), which significantly reduces the number of such compilation errors.
  • Comment out anything that prevents code compilation (assuming you don't need these parts)

You do not need to deal with non-compiling code, but those who committed it. If more people are working in this project, everyone should solve this problem on their local machine (find out why it does not compile, track erroneous classes, exclude / comment on these classes, if your code does not depend on them, rebuild, etc.) . It is much more efficient to have only 1 person to fix the problem, and everyone else just updates its local repository.

-3
source share

All Articles