“The type java.util.Map$Entry cannot be resolved” (tomcat6 + JDK7)

血红的双手。 提交于 2019-12-22 22:39:27

问题


I've a JSP app which gives me the error:

The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

Stackoverflow is full of post about this error, but all of them get to solve just compiling the .java files using JDK7, plus using tomcat with same version (I mean, below to JDK8 which seems to be the problem, because some IDE version and tomcat versions doesn't support it).

The problem is that I've built my app (.java files) using JDK 1.7.0_79, plus I've my tomcat 6 server using the same one.

So there's no JDK 8 anywhere... Some screenshots with data:

My JVM directory:

Error stacktrace:

Tomcat process (running using JDK7):

Javac version used to compile:

Any idea about why do I still get this error?

Thank you in advance


回答1:


Run Tomcat with Java 6 or upgrade to Tomcat 7 and make sure you don't have some old pre-Java 5/pre-generics library on the classpath.

Why do you get this error? Somewhere in the JSP code (not your code, mind), is a dependency on java.util.Map.Entry. This could be in code which Jasper generates from your JSP.

It's not a direct dependency; rather your code (or the Java code generated from your JSP) needs something else which then needs java.util.Map.Entry

But the interface has changed in some way. Usually, that's with Java 8 because of the new static helper methods which they added: The name of the class is the same (which makes the error so confusing) but the API has changed and the code can't find something (or found something it didn't expect).

A similar problem can happen when you try to compile against a pre-generics class (even though that should work).

Even worse, import java.util.Map in your JSP works. It's the existing bytecode somewhere else that causes the trouble.

[EDIT]

In my /WEB-INF/lib/ folder I've: commons-fileupload, commons-io, poi and rt (may this one be the problem?)

Yes :-) rt.jar is the Java runtime. It contains java.* and in your case, a version of java.util.Map which doesn't match the one from your Java VM.

Remote it and it should work.




回答2:


I had the same problem with Eclipse Mars, JDK 8 and the Tomcat Maven Plugin. It was solved changing the plugin version to 2.2 in my pom.xml.




回答3:


I have tomcat-7.0.22 and jdk1.8.0_45 and I replaced the ecj-3.7.jar file that is in tomcat/lib directory with ecj-4.6.1.jar file that's included in the tomcat-8.0.43 and that got rid of the error. for more information take a look at this post How to change tomcat compiler



来源:https://stackoverflow.com/questions/30643933/the-type-java-util-mapentry-cannot-be-resolved-tomcat6-jdk7

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