简体   繁体   中英

All warnings as errors with the Eclipse Java compiler (3.6.2)

How do I treat warnings as errors with the Eclipse Java compiler (ECJ) 3.6.2 * when running from the command-line ?

Newer versions (at least, 3.8.2) have the -err:all flag, however this isn't available in 3.6.2. Do I have any other options?

I've found this question ( Javac: Treat warnings as errors ) which recommends the undocumented -Werror flag, but that only seems to work for javac.

Note: For various reasons completely out of my control, I must use ECJ 3.6.2. So switching to a newer version or javac is not an option (at least, not in the immediate future)!


* Also seems to be known as the "JDT Core Batch Compiler" .

I don't think there's a way to specify err:all, but there's a decent workaround:

  1. Create an eclipse project.
  2. Project > Properties > Java Compiler > Errors / Warnings.
  3. Enable project specific settings.
  4. Set everything to Error level by hand (annoying, but a one time operation).
  5. That generates a org.eclipse.jdt.core.prefs file.
  6. Use the project/.settings/org.eclipse.jdt.core.prefs file in your compile process.

Here's an example using ant:

<javac srcdir="${test-unit.dir}" destdir="${target-test-classes.dir}" 
        classpathref="test.classpath" source="1.6" target="1.6" debug="true" 
        includeAntRuntime="false" compiler="org.eclipse.jdt.core.JDTCompilerAdapter">
    <compilerclasspath location="./libs/ecj-3.7.2.jar" />
    <compilerarg line="-time -properties .settings/org.eclipse.jdt.core.prefs" />
</javac> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM