【发布时间】:2018-09-07 13:35:23
【问题描述】:
AFAIK 如果我使用 WebServlet 注释,我不应该需要 web.xml。 我正在尝试使用 gradle 的 Google App Engine Standard 本地服务器,但尝试查找 web.xml 失败。
C:\Projects\x\x\Research\testeng>gradle appengineRun
2018 年 3 月 28 日 下午 1:17:18 java.util.prefs.WindowsPreferences
警告: 无法在根目录打开/创建首选项根节点 Software\JavaSoft\Prefs 0x80000002。 Windows RegCreateKeyEx(...) 返回错误代码 5。
三月 2018 年 2 月 28 日下午 1:17:18 com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
严重:收到异常处理 C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml
com.google.apphosting.utils.config.AppEngineConfigException: 不能 定位 C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml
我做错了什么...?
我得到了一个 servlet 的存根
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
我的 build.gradle 非常接近 Using Gradle and the App Engine Plugin 中使用的内容:
buildscript { // Configuration for building
repositories {
jcenter() // Bintray's repository - a fast Maven Central mirror & more
mavenCentral()
}
dependencies {
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
}
}
repositories { // repositories for Jar's you access in your code
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
}
mavenCentral()
jcenter()
}
apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
sourceSets {
// main.kotlin.srcDirs += "src/main/kotlin"
main.java.srcDirs += "src/main/java"
}
dependencies {
compile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
compile 'jstl:jstl:1.2'
// Add your dependencies here.
// compile 'com.google.cloud:google-cloud:+' // Latest Cloud API's http://googlecloudplatform.github.io/google-cloud-java
testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.33'
testCompile 'org.mockito:mockito-all:1.10.19'
testCompile 'com.google.appengine:appengine-testing:+'
testCompile 'com.google.appengine:appengine-api-stubs:+'
testCompile 'com.google.appengine:appengine-tools-sdk:+'
}
// Always run unit tests
appengineDeploy.dependsOn test
appengineStage.dependsOn test
appengine { // App Engine tasks configuration
deploy { // deploy configuration
}
}
test {
useJUnit()
testLogging.showStandardStreams = true
beforeTest { descriptor ->
logger.lifecycle("test: " + descriptor + " Running")
}
onOutput { descriptor, event ->
logger.lifecycle("test: " + descriptor + ": " + event.message )
}
afterTest { descriptor, result ->
logger.lifecycle("test: " + descriptor + ": " + result )
}
}
group = "com.testeng" // Generated output GroupId
version = "1.0-SNAPSHOT" // Version in generated output
sourceCompatibility = 1.8 // App Engine Flexible uses Java 8
targetCompatibility = 1.8 // App Engine Flexible uses Java 8
【问题讨论】:
标签: java google-app-engine servlets google-cloud-platform build.gradle