vscode-java
vscode-java copied to clipboard
Cannot find the class file for javax.servlet.http.HttpServletResponse.
- Operating System: Ubuntu 20.04
- JDK version: openjdk 11.0.11
- Visual Studio Code version: 1.60.1
- Java extension version: v0.82.0
I have a java project that uses gradle. This project worked well with the java extension for a long time.
Now, when I run './gradlew assemble' from the command line, the project builds successfully.
When I load the project in VSCode I get the following errors...
{
"resource": "/myproj//java_server",
"owner": "_generated_diagnostic_collection_name_#1",
"code": "0",
"severity": 8,
"message": "The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.http.HttpServletResponse. Fix the build path then try building this project",
"source": "Java",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 1
}
{
"resource": "/myproj/java_server/src/main/java/framework/MessageHandler.java",
"owner": "_generated_diagnostic_collection_name_#1",
"code": "16777540",
"severity": 8,
"message": "The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files",
"source": "Java",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 2
}
Do you have the project available somewhere to try out ? I've seen such issues when the project expects to use some version of J2EE but maybe only J2SE is being resolved. Does the problem go away if you explicitly add a dependency from something like https://search.maven.org/artifact/jakarta.servlet/jakarta.servlet-api ?
I have had no luck with explicitly adding dependencies.
Here is a minimal reproduction example.
Also, I don't think this should have 'question' label, as it is a bug with a repro case.
Works for me
Try the "Java: Clean Java Language Server Workspace" command
Works for me
Are you running Ubuntu 20.04 with OpenJDK 11?
I'm also able to reproduce, regardless of JDK, on Fedora 34. Strangely, the project resolves and the HttpServletResponse is even located with go-to definition. Note, that I had to add the IOException, ServletException classes to the imports, or else this would just produce a compilation error for me, even on commandline with ./gradlew assemble
.
However, I clearly see 2 errors :
On MessageHandler.java : "The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files"
On the project : The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.http.HttpServletResponse. Fix the build path then try building this project
I also noticed the gradle wrapper validation kept flagging the project's version as untrusted, so I ran ./gradlew wrapper
and it seemed to make some modifications. Once, I tried importing the project again (after clearing the language server workspace, the errors disappared). Can you try running this to see if it solves the issue for you ?
I'm also able to reproduce, regardless of JDK, on Fedora 34. Strangely, the project resolves and the HttpServletResponse is even located with go-to definition. Note, that I had to add the IOException, ServletException classes to the imports, or else this would just produce a compilation error for me, even on commandline with
./gradlew assemble
.However, I clearly see 2 errors : On MessageHandler.java :
"The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files"
On the project :The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.http.HttpServletResponse. Fix the build path then try building this project
I also noticed the gradle wrapper validation kept flagging the project's version as untrusted, so I ran
./gradlew wrapper
and it seemed to make some modifications. Once, I tried importing the project again (after clearing the language server workspace, the errors disappared). Can you try running this to see if it solves the issue for you ?
These are the two errors I am seeing. In addition, I also continually get the untrusted dialog popping up as well.
I should also add, that this project worked for years on older versions of the extension.
Does the problem go away if you run ./gradlew wrapper
from commandline to update the wrapper jar (as mentioned above) ? It completely solved the errors for me.
I have a similar problem with MAC:
[Error - 12:48:07 PM] Nov 2, 2021, 12:48:07 PM Error occured while building workspace. Details:
message: The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletException. Fix the build path then try building this project; code: 0; resource: /Users/fox/Documents/workspace/plcProject/chronos;
message: The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files; code: 16777540; resource: /Users/fox/Documents/workspace/plcProject/chronos/src/main/java/it/fox/chronos/webgui/ControlJetty.java; line: 1
message: The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.Servlet. Fix the build path then try building this project; code: 0; resource: /Users/fox/Documents/workspace/plcProject/hermes;
message: The type javax.servlet.Servlet cannot be resolved. It is indirectly referenced from required .class files; code: 16777540; resource: /Users/fox/Documents/workspace/plcProject/hermes/src/main/java/it/fox/hermes/JettyServer.java; line: 1
[Error - 12:57:59 PM] Nov 2, 2021, 12:57:59 PM Error occured while building workspace. Details:
message: The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletException. Fix the build path then try building this project; code: 0; resource: /Users/fox/Documents/workspace/plcProject/chronos;
message: The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files; code: 16777540; resource: /Users/fox/Documents/workspace/plcProject/chronos/src/main/java/it/fox/chronos/webgui/ControlJetty.java; line: 1
message: The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.Servlet. Fix the build path then try building this project; code: 0; resource: /Users/fox/Documents/workspace/plcProject/hermes;
message: The type javax.servlet.Servlet cannot be resolved. It is indirectly referenced from required .class files; code: 16777540; resource: /Users/fox/Documents/workspace/plcProject/hermes/src/main/java/it/fox/hermes/JettyServer.java; line: 1
the trick of ./gradlew wrapper
not worked.
Regards, S.
I have tried the demo project posted above and I have the exact problem reported here:
The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class filesJava(16777540)
My Gradle dependencies are:
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.eclipse.jetty:jetty-servlet:9.4.19.v20190610
| \--- org.eclipse.jetty:jetty-security:9.4.19.v20190610
| \--- org.eclipse.jetty:jetty-server:9.4.19.v20190610
| +--- javax.servlet:javax.servlet-api:3.1.0
| +--- org.eclipse.jetty:jetty-http:9.4.19.v20190610
| | +--- org.eclipse.jetty:jetty-util:9.4.19.v20190610 -> 9.4.29.v20200521
| | \--- org.eclipse.jetty:jetty-io:9.4.19.v20190610
| | \--- org.eclipse.jetty:jetty-util:9.4.19.v20190610 -> 9.4.29.v20200521
| \--- org.eclipse.jetty:jetty-io:9.4.19.v20190610 (*)
+--- org.eclipse.jetty:jetty-client:9.4.19.v20190610
| +--- org.eclipse.jetty:jetty-http:9.4.19.v20190610 (*)
| \--- org.eclipse.jetty:jetty-io:9.4.19.v20190610 (*)
\--- org.eclipse.jetty:jetty-util:9.4.29.v20200521
Please, could you indicate me a workaround? I am stuck in a project I could not debug for this issue !!!
My info are:
- Operating System: Mac 11.2
- JDK version: OpenJDK Runtime Environment Temurin-11.0.13+8 (build 11.0.13+8)
- Visual Studio Code version: 1.61.2
- Java extension version: v1.0.0
Regards, S.
@rgrunber Can you remove the question label and apply an appropriate one?
Can you retry the project with the latest release, v1.1.0
. The errors disappear for me every time I update to the newer release.