WebServlet annotations are in use but GAE is trying to find web.xml

1

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
java
google-app-engine
servlets
google-cloud-platform
build.gradle
asked on Stack Overflow Mar 28, 2018 by rooste • edited Oct 24, 2018 by Ying Li

3 Answers

1

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 on Stack Overflow Mar 28, 2018 by Ying Li
0

Solved it.

I used appengine-web.xml identical to example in appengine-web.xml Reference. Added runtime element and removed unused stuff and it works. This is what it looks now:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <runtime>java8</runtime>
  <threadsafe>true</threadsafe>
</appengine-web-app>
answered on Stack Overflow Mar 28, 2018 by rooste
0

This is not an answer but a tip to save time in case others face similar situation.

I had both web.xml entries for some of the servlets and some WebServlet annotated servlets. In this case annotated servlets are not registered as handlers in GAE Java Standard environment. Locally there is no issue.

answered on Stack Overflow May 14, 2020 by v7r

User contributions licensed under CC BY-SA 3.0