Before you begin
Before running and deploying this sample, take the following steps:-
Use the GCP Console to create a new GCP project,
create an App Engine application:
Go to App Engine When prompted, select the region where you want your App Engine application located.
- Install the following prerequisites
- Download and install git.
-
Download and install the Google Cloud SDK:
Download the SDK - After you download and install invoke the
following commands:
gcloud init gcloud auth application-default login
- Update to the latest version of Cloud SDK and all components:
gcloud components update - This quickstart uses Apache Maven version 3.5 or greater to build, run, and deploy the sample app. For details about installing Maven, see Using Apache Maven and the App Engine Plugin.
Download the Hello World app
We've created a simple Hello World app for the Java 8 runtime so you can quickly get a feel for deploying an app to the App Engine standard environment.Download the sample app and navigate into the app directory:
-
Clone the Hello World sample app repository to your local machine:
Alternatively, download the sample as a zip file and extract it.git clone https://github.com/GoogleCloudPlatform/getting-started-java.git
-
Change to the directory that contains the sample code:
cd getting-started-java/appengine-standard-java8/helloworld
Run Hello World on your local machine
To run the Hello World app on your local computer:-
Start the local Jetty web server using the Jetty Maven plugin:
mvn appengine:run -
In your web browser, visit the following address:
http://localhost:8080 -
You can see the Hello World message from the sample app displayed in the
page.
-
In your terminal window, press Ctrl+C to exit the web server.
Deploy and run Hello World on App Engine
To deploy your app to the App Engine standard environment:- Deploy the Hello World app by running the following
command
from the
getting-started-java/appengine-standard-java8/helloworlddirectory:
mvn appengine:deploy
Wait for the deployment to finish. - Launch your browser and view the app at
http://YOUR_PROJECT_ID.appspot.com, by running the following command:
gcloud app browse
Congratulations! You've deployed your first Java 8 app to App Engine standard environment!
See the following sections for information about cleaning up as well as links to the possible next steps that you can take.
What's next
Learn the whole platform
Now that you know what it's like to develop and deploy App Engine apps, you can stretch out and see the rest of Google Cloud Platform. You already have the Google Cloud SDK installed and that gives you the tools to interact with products like Google Cloud SQL, Google Cloud Storage, Google Cloud Datastore, and more. For a guided walkthrough that teaches you how to create an application that uses the entire platform, not just App Engine, check out our quickstart on creating the Bookshelf app.Learn about the App Engine standard environment
Here are some topics to help continue your learning about App Engine.Hello World code review
Hello World is the simplest possible App Engine app, as it contains only one service, has only one version, and all of the code is located within the app's root directory. This section describes each of the app files in detail.
HelloServlet.java
The HelloServlet.java file specifies a URL pattern that describes where the
app will listen for requests, and responds to any requests with the 'Hello
World' message.- For more information on how the Java 8 runtime works, see The Java 8 Runtime.
pom.xml
Hello World also includes a pom.xml file, which contains information about
the project like its dependencies and the build target, including the required
lines for using the Maven plugin:- For more information about
pom.xmlfiles, see the Maven documentation.
appengine-web.xml
The appengine-web.xml file contains certain required settings, such as the java8
setting for the <runtime> element that tells App Engine to run this
application in the Java 8 runtime:
No comments:
Post a Comment