Btc Sources Btc Sources - 3 months ago 33
Java Question

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

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:

enter image description here

Error stacktrace:

enter image description here

Tomcat process (running using JDK7):

enter image description here

Javac version used to compile:

enter image description here

Any idea about why do I still get this error?

Thank you in advance

Answer

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.