首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VSCode Java扩展给出错误“找不到javax.servlet.http.HttpServletResponse的类文件”。

VSCode Java扩展给出错误“找不到javax.servlet.http.HttpServletResponse的类文件”。
EN

Stack Overflow用户
提问于 2021-09-19 20:21:25
回答 2查看 189关注 0票数 2

我有一个使用gradle作为构建系统的java项目。我使用Redhat的Java扩展在VSCode中进行开发。我正在使用openjdk 11在Ubuntu 20.04上进行开发。

当我从命令行使用'./gradlew assemble‘构建项目时,我没有得到任何构建错误。

但是当我在vscode中打开项目时,我在problems视图中看到以下问题...

代码语言:javascript
复制
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

还有..。

代码语言:javascript
复制
The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files

我的build.gradle如下...

代码语言:javascript
复制
plugins {
  id 'com.google.cloud.tools.jib' version '2.4.0'
}

apply plugin: 'java'

// Use maven repository
repositories {
    mavenCentral()
    google()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'org.eclipse.jetty:jetty-servlet:9.4.19.v20190610'
    implementation 'org.eclipse.jetty:jetty-client:9.4.19.v20190610'
    implementation group: 'org.eclipse.jetty', name: 'jetty-util', version: '9.4.29.v20200521'

    implementation 'mysql:mysql-connector-java:8.0.16'
    implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.16'
    implementation 'org.apache.commons:commons-dbcp2:2.7.0'
    implementation 'org.jdbi:jdbi3-core:3.10.1'
    implementation 'com.google.firebase:firebase-admin:6.11.0'
    implementation 'com.google.apis:google-api-services-oauth2:v1-rev155-1.25.0'

    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
    implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'

    implementation 'com.github.bhlangonijr:chesslib:1.2.3'

    // compile project('chesslib')
    //runtime files('../../chesslib/build/libs/chesslib-1.1.12.jar')
}

task runServer(type: JavaExec) {
    enableAssertions = true
    classpath = sourceSets.main.runtimeClasspath 
    main = 'ChessServer'
} 

task runClient(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath 
    main = 'ChessClient'
    standardInput = System.in // without this, using Scanner on System.in won't work
}

task runCLITestApp(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath 
    main = 'CLITestApp'
    standardInput = System.in
}

// use cloudBuilder.py to invoke this jib task to build the container
// use cloudConfiguration.json to configure things like container version.
jib {
    if (project.hasProperty('googleCloudProjectName') && project.hasProperty('imageName')) {
        to {
          image = "gcr.io/$googleCloudProjectName/$imageName"
        }
        container {
            mainClass = 'ChessServer'
            ports = ['8080']
            creationTime = "USE_CURRENT_TIMESTAMP"
        }
    }
}

// make sure the required project properties are set for jib
task jibCheck {
    doLast {
        if (!project.hasProperty('googleCloudProjectName'))
            throw new GradleException("When invoking the jib task, make sure to pass the cli arg -PgoogleCloudProject=[myGoogleCloudProject]\nThis should be the name of the google cloud project which container registry you want to push to.");
        if (!project.hasProperty('imageName'))
            throw new GradleException("When invoking the jib task, make sure to pass the cli arg -PimageName=[imageName]");
    }
}
tasks.jib.dependsOn tasks.jibCheck

// src/main/jib is the default folder that jib looks for files to add to your container
// these files will be placed in the root / dir of the container
task moveFilesForJib(type: Copy) {
    from "releaseFiles"
    into "src/main/jib"
}
tasks.jib.dependsOn tasks.moveFilesForJib
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-09-29 15:40:38

解决方案是运行

代码语言:javascript
复制
./gradlew wrapper

然后在vscode中运行Java: Clean Workspace。

票数 0
EN

Stack Overflow用户

发布于 2021-09-20 08:49:20

将以下内容添加到build.gradle。重新构建项目后,查看错误是否消失。

代码语言:javascript
复制
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69246821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档