我有一个使用gradle作为构建系统的java项目。我使用Redhat的Java扩展在VSCode中进行开发。我正在使用openjdk 11在Ubuntu 20.04上进行开发。
当我从命令行使用'./gradlew assemble‘构建项目时,我没有得到任何构建错误。
但是当我在vscode中打开项目时,我在problems视图中看到以下问题...
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还有..。
The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files我的build.gradle如下...
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发布于 2021-09-29 15:40:38
解决方案是运行
./gradlew wrapper然后在vscode中运行Java: Clean Workspace。
发布于 2021-09-20 08:49:20
将以下内容添加到build.gradle。重新构建项目后,查看错误是否消失。
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'https://stackoverflow.com/questions/69246821
复制相似问题