metamatt
metamatt

Reputation: 14419

Can one specify Java warning settings per project in Eclipse?

I have a Java project which is a combination of human-written Java code and Java code generated by axis2.

The axis2 generated code provokes thousands of warnings from the Java compiler (either javac or the one built into Eclipse). Examples of warnings: dead code, use of raw list and array types predating Java generics, etc. (more at http://www.coderanch.com/t/501752/Web-Services/java/Axis-Generate-without-Warnings). I'd like to silence and ignore these specific warnings in the generated code, but not the human-written code.

I've seen How to add -Xlint:unchecked option or any javac option in Eclipse? and that allows me to disable the relevant warnings via Window->Preferences, but workspace-wide, which is not what I want. Is there a way to do this on a per-project basis?

If not, how do people deal with generated code without ignoring warnings that would be useful to humans?

Upvotes: 3

Views: 1427

Answers (3)

Kenster
Kenster

Reputation: 25390

This doesn't directly address your question. But the approach we've taken to dealing with warnings in generated code is not to store the generated code in the filesystem. Instead, we store the generated code in a jar which can be included in the service package. The basic process is as follows:

  1. Create a temporary directory and run wsdl2java to generate code, placing its output in the temporary directory.

  2. Compile the code into a set of class files.

  3. Store the compiled classes and the resource files into a jar. Store the source code in a zip.

  4. Remove the temporary directory.

Once you've done this, add the jar to your classpath, then edit your build configuration and add the zipfile as a "source attachment". Eclipse will show you the correct source when you navigate to one of the generated classes, but it won't parse the code for warnings. The jar with the generated code in it can be added to your packaged service; with an AAR package, it goes in a subdirectory called "lib".

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359816

You can enable lots of different options on a per-project basis. Assuming you're using Helios, here's how to configure warnings on a particular project:

  1. Right-click the project (or select the project, then Alt+Enter)
  2. Java Compiler → Errors/Warnings
  3. Check "Enable project specific settings" (does the missing hyphen bug you? It bugs me)
  4. Configure away!

illustrious illustration!

Upvotes: 8

VonC
VonC

Reputation: 1324218

The multiple projects approach suggested by Matt is the right solution (since you can remove all warnings for a given project)

To try to do so within the same project has been:

So far, there isn't a way to "ignore warnings from certain source folders".

Upvotes: 3

Related Questions