简体   繁体   中英

Using app.yaml in Google AppEngine

I'm running a Java app on AppEngine, and I want to use app.yaml. I've read the docs and created a app.yaml app inside the WEB-INF folder with the following contents

application: myprojectname
version: 1
runtime: java
api_version: 1

welcome_files:
  - index.jsp
  - index.html

handlers:
- url: /oblivion/*
  servlet: myprojectname.CronUpdater

Where myprojectname is the name of the project.

However when I access localhost:8888/oblivion Or localhost:8888/oblivion/ I get a

HTTP ERROR 404

Problem accessing /oblivion. Reason:

NOT_FOUND

What could be the reason?

This is the structure of the directory (truncated)

pratik@pratik-desktop:~/workspace/myprojectname/war$ ls -LR
index.html  index.jsp  WEB-INF

./WEB-INF:
appengine-generated  app.yaml  cron.yaml  logging.properties
appengine-web.xml    classes   lib        web.xml

...

In appengine, there is two environment type (as of now) :

  • Flexible Environment
  • Standard Environment

You can't use appengine-web.xml and app.yaml at the same time :

  • Flexible environment use app.yaml to configure all the things that appengine need to know
  • Standard environment use appengine-web.xml and logging.properties

Here I assume you want to use the appengine in ' Flexible Environment ' mode. Usually, the app.yaml is located in the appengine folder, just inside your main folder.

From the Google Cloud Platform doc , you should have :

myprojectname/
 [pom.xml]         (optional, only if you use maven)
 [build.gradle]    (optional, only if you use gradle)
 [index.yaml]      (optional, only if you use cloud datastore)
 [cron.yaml]       (optional, only if you use cron job)
 [dispatch.yaml]   (optional, only if you route to services)
 src/main/
   appengine/
     app.yaml
   java/
     com.example.mycode/
       MyCode.java
   webapp/
     [index.html]
     [index.jsp]
     WEB-INF/
       [web.xml]

One last thing : handlers should be defined in the web.xml file. In app.yaml , you should just have :

handlers:
  - url: /.*
    script: this field is required, but ignored

and in your web.xml something like this :

<servlet>
    <servlet>
      <servlet-name>CronUpdater</servlet-name>
      <servlet-path>myprojectname.CronUpdater</servlet-path>
    </servlet>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CronUpdater</servlet-name>
    <url-pattern>/oblivion/*</url-pattern>
</servlet-mapping>

Hope this helps !

Instead of using myprojectname.CronUpdater, you need to list the full package and class of the servlet. So if CronUpdater is in package

com.mycompany.servlets

you'll need to put

servlet: com.mycompany.servlets.CronUpdater

in your app.yaml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM