2

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?

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
bladepit
  • 853
  • 5
  • 14
  • 29

4 Answers4

5
<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>
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
2

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,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • it seems to be the right way but how i can do that. can i add this: @SuppressWarnings("all") on the top of my class after the imports to suppress all warnings? did you the know the option for ant? need i set the -Xlint to an specific value? – bladepit Nov 26 '12 at 18:14
  • `ant`doesn't care about these, `javac` does. Show us the warning you get, and then we'll be able to help much better. – Anders R. Bystrup Nov 26 '12 at 18:56
  • this is the warning: [javac] /Users/Jochen/Documents/workspace/MuDiSAR/de/mudisar/dataloader/gui/CustomJFileChooser.java:28: warning: FilePane is internal proprietary API and may be removed in a future release [javac] import sun.swing.FilePane; – bladepit Nov 26 '12 at 19:22
  • That particular warning cannot be `@SuppressWarnings`'ed. I've edited my answer. – Anders R. Bystrup Nov 27 '12 at 10:29
0

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

Vishal
  • 3,189
  • 1
  • 15
  • 18
  • i dont' see what i have to do. what i need in my class files and what in my ant build file. i know this page but i can't handle it so that my warnings from an sepecific class will suppress – bladepit Nov 26 '12 at 19:57
0

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.

Community
  • 1
  • 1
mikeslattery
  • 4,039
  • 1
  • 19
  • 14
  • "internal proprietary API" type warnings are not suppressible in this manner, cf. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6476630. – Anders R. Bystrup Nov 27 '12 at 10:41