bladepit
bladepit

Reputation: 873

Ant compiler warnings for specific class file

I want to ignore warnings from ant which are thrown by an specific file.

It is not mandatory why there are warnings i only want to find a way that any ignore the warnings form an specific class file.

Is there a way to do that?

Upvotes: 2

Views: 2874

Answers (4)

Ray Hulha
Ray Hulha

Reputation: 11221

<target name="compile">
    <mkdir dir="${classes.dir}" />
    <javac
        classpathref="project.classpath"
        bootclasspath="${javac.bootclasspath}"
        compiler="${javac.compiler}"
        debug="${javac.debug}"
        deprecation="${javac.deprecation}"
        destdir="${classes.dir}"
        fork="${javac.fork}"
        memoryMaximumSize="${javac.memoryMaximumSize}"
        nowarn="${javac.nowarn}"
        srcdir="${source.dir}"
        source="${javac.source}"
        target="${javac.target}"
        encoding="UTF-8"
    >
        <compilerarg value="-XDignore.symbol.file"/>

    </javac>
</target>

Upvotes: 5

Anders R. Bystrup
Anders R. Bystrup

Reputation: 16050

I take it you mean "suppress compilation warnings from javac when running an Ant script"?

You don't supply an example of a warning, but in general you could look into the @SuppressWarnings annotation. Sadly, only "unchecked" is required byt the JLS, while all others are implementation dependent - you can try a

localhost:~$ javac -X
  -Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,
          serial,finally,overrides,-cast,-deprecation,-divzero,-empty,-unchecked,
          -fallthrough,-path,-serial,-finally,-overrides,none}

to see the ones supported on your chosen JDK.

Edit: It is not possible to suppress the "internal proprietary API" type warnings in this manner, cf. this Bug ID. It should, however, be possible with the (undocumented) -XDignore.symbol.file command line option for javac (see eg. bug 6544224).

The real solution is of course to not use these APIs...

Cheers,

Upvotes: 2

mikeslattery
mikeslattery

Reputation: 4119

Add @SuppressWarnings to your class definition. Example:

@SuppressWarnings
public class MyClass {
}

You can suppress specific warnings by passing a string argument like: @SuppressWarnings("unchecked"). See What is the list of valid @SuppressWarnings warning names in Java? For a list.

Upvotes: 0

Vishal
Vishal

Reputation: 3279

javac ant task has nowarn property to switch off all the warnings at the time of compiling. But to mute warnings from one specific class, you will have to modify your java file only.

Here it goes http://ant.apache.org/manual/Tasks/javac.html

Upvotes: 0

Related Questions