Disable generics validation in Eclipse via M2E

你。 提交于 2019-12-11 02:05:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!