Issue
AFAIK if I use WebServlet annotation I should not need web.xml. I'm trying Google App Engine Standard local server with gradle but it fails trying to find web.xml.
C:\Projects\x\x\Research\testeng>gradle appengineRun
Mar 28, 2018 1:17:18 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Mar 28, 2018 1:17:18 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
SEVERE: Received exception processing C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml
com.google.apphosting.utils.config.AppEngineConfigException: Could not locate C:\Projects\x\x\Research\testeng\build\exploded-testeng\WEB-INF\web.xml
What am I doing wrong...?
I got my stub of a 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 {
}
}
my build.gradle is pretty close what was used in 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
Solution
You need both the web.xml and appengine-web.xml if you are using GAE standard with Java as they are used to describe how your app is configured.
You can see the documents for details on which configuration setting you need for your application.
Answered By - Ying Li
Answer Checked By - Gilberto Lyons (JavaFixing Admin)