1

I am working on an Apache Maven dynamic web project on eclipse. It uses static files (html, css, js) and a Java servlet. When I deploy my project to the google app engine, the Java servlet does not handle http requests. The project runs perfectly locally. The servlets use @WebServlet, but adding url-mapping to the xml doesn't work either. I deploy using mvn appengine:update. To troubleshoot, I decided to take a java class from a google github repository. I added the java file to my servlet folder and after deploying I get 404 errors for it as well.

This is my WebServlet annotation:

@WebServlet(name = "requests", description = "Requests: Trivial request",
    urlPatterns = "/requests")

Here is the bulk of my pom.xml:

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>1.9.54</version>
  </plugin>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
      <warSourceDirectory>www</warSourceDirectory>
    </configuration>
  </plugin>
</plugins>
</build>
 <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
 </properties>
 <dependencies>
 <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <type>jar</type>
    <scope>provided</scope>
 </dependency>
</dependencies>

Where am I going wrong?

Edit:

<?xml version="1.0" encoding="UTF-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

  <threadsafe>true</threadsafe>
  <runtime>java8</runtime>
  <warmup-requests-enabled>true</warmup-requests-enabled>
  <module>default</module>
  <automatic-scaling>
    <min-idle-instances>1</min-idle-instances>
    <max-idle-instances>automatic</max-idle-instances>
    <min-pending-latency>500ms</min-pending-latency>
    <max-pending-latency>automatic</max-pending-latency>
    <max-concurrent-requests>50</max-concurrent-requests>
  </automatic-scaling>
</appengine-web-app>
4
  • Can you post your appengine-web.xml? The production App Engine standard environment only supports Java 7 and Servlet 2.5. App Engine standard environment for Java 8 is now in beta, but requires an explicit <runtime>java8</runtime> to be added to your appengine-web.xml. – Brian de Alwis Jul 24 '17 at 15:54
  • @BriandeAlwis I updated my post. I did have that tag included in the xml. – Alec Jul 28 '17 at 3:21
  • Finally found a moment to try to reproduce this and… it works for me. I used your same appengine-web.xml, but I don't have my source in src and www, and I don't pin a version on maven-war-plugin. I can only suggest you look at the "Tools" menu for in the Developer Console > App Versions and look at the "Debug" and verify that the uploaded archive looks as you expect. And check the logs to see what if there's anything anomalous reported. – Brian de Alwis Aug 3 '17 at 19:24
  • I had the same problem, and it happens to work (locally and on deploy) when there is no web.xml file in WEB-INF. I don't know if this is a bug or intended behaviour. – rkouye Sep 28 '17 at 15:48
0

I was able to reproduce your issue. It seems you are missing the cloud tools plugin. To resolve it, add the following on your <plugins>:

<plugin>
   <groupId>com.google.cloud.tools</groupId>
   <artifactId>appengine-maven-plugin</artifactId>
   <version>1.3.1</version>
   <configuration>
      <deploy.promote>true</deploy.promote>
      <deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>          
   </configuration>
</plugin>

If the above does not mitigate your issue, please post full error logs. Thanks

0

The Servlet 3.1 annotations do not seem to work in the Local Development Server at the time I am posting this.

I got the same code to work when actually deployed to GAE, but nothing with @WebServlet works with the local development environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.