问题
I have this legacy project coming from Java 1.4 (ancient, I know!) that has all the List and ArrayList with unspecified generic types. I have migrated this project lately to Maven for easier build automation.
Now when I import it to Eclipse I see tons of warnings like ArrayList is a raw type. References to generic type ArrayList should be parameterized. Is there any way to instruct the M2E in pom.xml to have those check automatically disabled when importing this project into Eclipse?
Note: I want the project to be compiled under Java 1.6.
回答1:
Eclipse is showing the warnings, not necessarily the m2e plugin.
In Eclipse, you can configure your projects targeted compiler like so:
- Right click your project in the Package Explorer
- Select Java Compiler
- Click Enable project specific settings
- Change the Compiler compliance level to 1.4
This should rid the warnings you're seeing in Eclipse.
As @Duncan Jones has pointed out, add your targeted compiler to your projects pom file if you want to build using Maven via the command line, without any compile time warnings.
Update
Failing this, you could add @SuppressWarnings("rawtypes")
as a class level annotation if you're happy to ignore the problem. This would give you the IDE independent solution you're looking for.
来源:https://stackoverflow.com/questions/13718815/disable-generics-validation-in-eclipse-via-m2e