Classpath for JSP validation
Hello,
I'm attempting to compile/validate JSPs in my web project. On the editor a JSP seems to be fine, however when I validate the same JSP, I get errors such as:
Error:The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
Error:(64, 0) The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files
Error:(120, 0) The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files
These errors are not limited to JDK classes; my custom classes referred in JSP scriptlets are also showing up as unable to resolve.
This seems to be a classpath issue, but I do have all necessary dependencies set up for web module in which my JSPs reside.
And as mentioned, in the editor there are no such issues apparent.
Thanks.
Please sign in to leave a comment.
Check the JDK language level used for the project and modules, try using 1.8, see http://stackoverflow.com/a/12900859/104891.
While it was missing just in the Settings->Compiler->Java Compiler, after adding 1.8, there was no difference to the outcome of the JSP validation.
Please share a small sample project to reproduce the problem.
How do I go about uploading the sample project?
I created a New project from the maven-archetype-webapp, and when I validate the index,jsp that was automatically created, I see:
Error:The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files.
I ensured that for this new maven project, the JDK language level is 1.8 across the board, as per the link you had shared earlier.
Thanks.
See https://intellij-support.jetbrains.com/hc/articles/206869619.
I uploaded demo.tgz via https://uploads.services.jetbrains.com/ . However, the upload didn't generate any identifier for me to pass on to you.
Let me know if this works.
Validate JSP action on this project doesn't give me any errors/warnings. How exactly can I reproduce it?
I just right-click on the JSP and choose Validate file index.jsp to cause the issue in my environment.
I did notice that when I Make the sample project, I am not seeing the error. Whereas when I make my original project, I run into the error (among others).
This is the version of Idea that I have: idea-IU-141.3058.30
Your IntelliJ IDEA version is too old, this was fixed long time ago, please update.
I downloaded an eval version of the latest IDEA release, and yes this fixes most of my problems. Thanks.
On the original project, I am seeing a bunch of issues of this kind:
"Error:Only a type can be imported. org.joda.time.DateTime resolves to a package"
This is showing up in JSPs that include another common JSP, that for convenience imports common classes:
<%@include file="../../common/SharedMethods.jsp" %>
In the above common JSP, DateTime is imported as below:
<%@ page import="org.joda.time.DateTime" %>
I've researched and most of the problems are in the area where there is an actual deployment and folks are pre-compiling JSPs using Jasper.
In this case, I am in IDEA so I don't think those solutions apply.
I realize this is a different issue, and I can open another post if required. But it's in the general area of JSP validation in IDEA.
Feel free to file a report at https://youtrack.jetbrains.com/issues/IDEA with the sample project to reproduce attached.
While trying to reproduce this in the demo project, I saw that the issue was caused due to the JodaTime library being present in the test library and not in the compile library.
The web module included both the test and the compile library.
While open in the editor, the JSP did not complain about the org.joda.time.DateTime import, since it was present in the classpath via the test library dependency.
But when the JSP is being validated, it must be using the compile library dependency alone and since JodaTime is not present there, it gives the somewhat misleading error:
"Error:Only a type can be imported. org.joda.time.DateTime resolves to a package"
The misleading error is a Jasper construct, so I don't think IDEA can do anything about it. This is what is reported by people who were using Jasper directly via Ant or other build tools.
What classpath/dependencies does Jasper+IDEA use while validating? From what I'm seeing (I could be mistaken), it doesn't seem to be matching the web module's dependency list.
My issue is otherwise resolved and the original problem was solved by upgrading my IDEA version as advised. Thanks.
It should use the classpath of the module, there is no other place to configure the classpath specifically for Jasper in IntelliJ IDEA.