简体   繁体   中英

M2Eclipse shows an error, but Maven compiles fine

I always have some of the most obscure problems, and often I'll find similar problems but ones not applicable to my actual problem...

Anyways, I'm having an issue with M2Eclipse showing an error in Eclipse. Currently, my POM.xml references xml-apis:xml-apis of some version (yes, I'm aware of the issue with Xerces), and apparently, xml-apis replaces and not overrides classes in the JDK. One specific example of such is org.w3c.dom.Element in rt.jar in the JDK; this class exists, but xml-apis has a class with the same name and package structure, effectively replacing it -- or so Eclipse thinks.

What makes this bad for me is that since xml-apis replaces this implementation instead of overriding it, there are references in the code (which I've been tasked with migrating from Ant to Maven, where you could just change the build order and Eclipse would stop having a whinge) where the libraries to not match up... For example, Element e; e.getTextContext(); Element e; e.getTextContext(); would yield an error such that " The method getTextContent() is undefined for the type Element ." This error only shows in the editor and the Problems window in Eclipse, though. But Maven compiles it just fine... So why is Eclipse showing an error?

To the best of my knowledge, there's no way to change the build order in a Maven project in Eclipse to make it stop doing this. Does anyone have any solutions for this?

For reference (if it matters, which I doubt) I'm running Windows 7 Professional, compiling with JDK 1.6, and I'm using Maven 3.0.4.

select your project > right click > properties > java build path > order and export > select JRE entry and hit down

在这里,您可以控制类路径条目的顺序,因此,如果您希望从maven中获取jar,请先将其移至JRE条目之前

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM