Skip to content

Commit 2fe9b4a

Browse files
authored
Add one Java17 bundled services sample, and generic README. (GoogleCloudPlatform#6909)
* Add one Java17 bundled services sample, and generic instructions to use the other java8 samples. * doc: add the mvn appengine:deployIndex step for deploying the datastore index file. doc: add the mvn appengine:deployIndex step for deploying the datastore index file. * Update README.md * Use symlinks to unchanged code from the Java8 sample. * Make symlinks ot unchanged code and fixed documentation and pom files. * ->java17 runtime. * Use symlinks to java8 files.
1 parent eebc1d1 commit 2fe9b4a

38 files changed

Lines changed: 376 additions & 18 deletions

appengine-java11-bundled-services/README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ where you need to define the Java11 runtime and declare you need the App Engine
4949
</appengine-web-app>
5050
```
5151

52-
While the Java11 runtime is in Beta, in order to deploy the application, you can use the `beta` value for the `gcloudMode` Cloud SDK parameter like:
53-
5452
```shell
55-
mvn appengine:deploy -Dapp.deploy.gcloudMode=beta
53+
mvn appengine:deploy
5654
```
5755

5856

@@ -72,17 +70,17 @@ This sample demonstrates how to use the App Engine Datastore APIs in a Java11 we
7270

7371
You can execute the following steps to transform the java8 appengine-web.xml file to a java11 appengine-web.xml file:
7472

75-
```shell
76-
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
77-
cd java-docs-samples
78-
cp -pr appengine-java8 /tmp/java11-samples
79-
cd /tmp/java11-samples
80-
# On Linux:
81-
shopt -s globstar dotglob
82-
for f in **/appengine-web.xml; do sed -i 's.<runtime>java8</runtime>.<runtime>java11</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
83-
# on MacOS
84-
for f in **/appengine-web.xml; do sed -i'' -e 's.<runtime>java8</runtime>.<runtime>java11</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
85-
```
73+
```shell
74+
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
75+
cd java-docs-samples
76+
cp -pr appengine-java8 /tmp/java11-samples
77+
cd /tmp/java11-samples
78+
# On Linux:
79+
shopt -s globstar dotglob
80+
for f in **/appengine-web.xml; do sed -i 's.<runtime>java8</runtime>.<runtime>java11</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
81+
# on MacOS
82+
for f in **/appengine-web.xml; do sed -i'' -e 's.<runtime>java8</runtime>.<runtime>java11</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
83+
```
8684
8785
You will see in the `tmp/java11` directory all the correct code samples to compile and deploy to the Java11 AppEngine runtime, with bundled services.
8886
Just follow the same documentation as the [Java8 samples][java8-samples].

appengine-java11-bundled-services/datastore/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ To see the results of the sample application, open
3939

4040
## Deploying
4141

42-
In the following command, replace YOUR-PROJECT-ID with your
43-
[Google Cloud Project ID](https://developers.google.com/console/help/new/#projectnumber)
44-
and SOME-VERSION with a valid version number.
45-
4642
```sh
4743
mvn clean package appengine:deploy
44+
mvn appengine:deployIndex
4845
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Google App Engine Standard Environment Samples for Java 17 Bundled Services
2+
3+
This is a repository that contains Java code samples for [Google App Engine
4+
standard environment Java 17 Bundled Services][ae-docs].
5+
The Google App Engine standard environment Java 17 Bundled Services is an environment
6+
as close as possible as the original Google App Engine standard environment Java 8
7+
which is using WAR packaging, GAE APIs and configured via appengine-web.xml instead of app.yaml
8+
9+
[ae-docs]: https://cloud.google.com/appengine/docs/standard/java-gen2/services/access
10+
11+
## Prerequisites
12+
13+
### Download Maven
14+
15+
These samples use the [Apache Maven][maven] build system. Before getting
16+
started, be sure to [download][maven-download] and [install][maven-install] it.
17+
When you use Maven as described here, it will automatically download the needed
18+
client libraries.
19+
20+
[maven]: https://maven.apache.org
21+
[maven-download]: https://maven.apache.org/download.cgi
22+
[maven-install]: https://maven.apache.org/install.html
23+
[java8-samples]: https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/appengine-java8#readme
24+
25+
### Create a Project in the Google Cloud Platform Console
26+
27+
If you haven't already created a project, create one now. Projects enable you to
28+
manage all Google Cloud Platform resources for your app, including deployment,
29+
access control, billing, and services.
30+
31+
1. Open the [Cloud Platform Console][cloud-console].
32+
1. In the drop-down menu at the top, select **Create a project**.
33+
1. Give your project a name.
34+
1. Make a note of the project ID, which might be different from the project
35+
name. The project ID is used in commands and in configurations.
36+
37+
[cloud-console]: https://console.cloud.google.com/
38+
39+
40+
## Development differences between App Engine Java8 and Java17 Bundled Services
41+
42+
The only difference between a Java8 application and a Java17 application is in the `appengine-web.xml` file
43+
where you need to define the Java17 runtime and declare you need the App Engine APIs:
44+
45+
```XML
46+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
47+
<runtime>java17</runtime>
48+
<app-engine-apis>true</app-engine-apis>
49+
</appengine-web-app>
50+
```
51+
52+
While the Java17 runtime is in Beta, in order to deploy the application, you can use the `beta` value for the `gcloudMode` Cloud SDK parameter like:
53+
54+
```shell
55+
mvn appengine:deploy -Dapp.deploy.gcloudMode=beta
56+
mvn appengine:deployIndex
57+
```
58+
59+
60+
Everything else should remain the same in terms of App Engine APIs access, WAR project packaging, and deployment.
61+
This way, it should be easy to migrate your existing GAE Java8 applications to GAE Java17.
62+
63+
## Samples
64+
65+
### App Engine Datastore with Java17
66+
67+
This sample demonstrates how to use the App Engine Datastore APIs in a Java17 web application on Google App Engine Java17.
68+
69+
- [Documentation][ae-docs]
70+
- [Code](https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/appengine-standard-java11-bunded-services/datastore)
71+
72+
### How to change an App Engine Java 8 application to App Engine Java17 bundled services
73+
74+
You can execute the following steps to transform the java8 appengine-web.xml file to a java17 appengine-web.xml file:
75+
76+
```shell
77+
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
78+
cd java-docs-samples
79+
cp -pr appengine-java8 /tmp/java17-samples
80+
cd /tmp/java17-samples
81+
# On Linux:
82+
shopt -s globstar dotglob
83+
for f in **/appengine-web.xml; do sed -i 's.<runtime>java8</runtime>.<runtime>java17</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
84+
# on MacOS
85+
for f in **/appengine-web.xml; do sed -i'' -e 's.<runtime>java8</runtime>.<runtime>java17</runtime><app-engine-apis>true</app-engine-apis>.' ${f}; done
86+
```
87+
88+
You will see in the `tmp/java17` directory all the correct code samples to compile and deploy to the Java17 AppEngine runtime, with bundled services.
89+
Just follow the same documentation as the [Java8 samples][java8-samples].
90+
91+
92+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Google Cloud Datastore Sample for App Engine Standard Java17 Bundled Services
2+
3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=appengine-java17-bundled-services/datastore/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
This sample demonstrates how to use [Google Cloud Datastore][java-datastore]
7+
from [Google App Engine standard Java17 bundled services environment][ae-docs].
8+
9+
[java-datastore]: https://cloud.google.com/appengine/docs/java/datastore/
10+
[ae-docs]: https://cloud.google.com/appengine/docs/standard/java-gen2/services/access
11+
12+
## Difference between App Engine Java8 and Java17 Bundled Services
13+
14+
The only difference between a Java8 application and a Java17 application is in the `appengine-web.xml` file
15+
where you need to define the Java17 runtime and declare you need the App Engine APIs:
16+
17+
```XML
18+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
19+
<runtime>java17</runtime>
20+
<app-engine-apis>true</app-engine-apis>
21+
</appengine-web-app>
22+
```
23+
24+
Everything else should remain the same in terms of App Engine APIs access, WAR project packaging, and deployment.
25+
This way, it should be easy to migrate your existing GAE Java8 applications to GAE Java17.
26+
27+
## Running locally
28+
29+
This example uses the
30+
[Cloud SDK Maven plugin](https://cloud.google.com/appengine/docs/java/tools/using-maven).
31+
To run this sample locally:
32+
33+
```sh
34+
mvn package appengine:run
35+
```
36+
To see the results of the sample application, open
37+
[localhost:8080](http://localhost:8080) in a web browser.
38+
39+
40+
## Deploying
41+
42+
43+
```sh
44+
mvn clean package appengine:deploy -Dapp.deploy.gcloudMode=beta
45+
mvn appengine:deployIndex
46+
47+
```
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2022 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
<packaging>war</packaging>
20+
<version>1.0-SNAPSHOT</version>
21+
<groupId>com.example.appengine</groupId>
22+
<artifactId>appengine-datastore-j17</artifactId>
23+
24+
<!--
25+
The parent pom defines common style checks and testing strategies for our samples.
26+
Removing or replacing it should not effect the execution of the samples in anyway.
27+
-->
28+
<parent>
29+
<groupId>com.google.cloud.samples</groupId>
30+
<artifactId>shared-configuration</artifactId>
31+
<version>1.2.0</version>
32+
</parent>
33+
34+
<properties>
35+
<maven.compiler.target>11</maven.compiler.target> <!-- or 17 to use JDK17 features.-->
36+
<maven.compiler.source>11</maven.compiler.source>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>com.google.appengine</groupId>
42+
<artifactId>appengine-api-1.0-sdk</artifactId>
43+
<version>2.0.4</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>javax.servlet</groupId>
48+
<artifactId>javax.servlet-api</artifactId>
49+
<version>3.1.0</version>
50+
<type>jar</type>
51+
<scope>provided</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.google.auto.value</groupId>
56+
<artifactId>auto-value</artifactId>
57+
<version>1.9</version>
58+
<scope>provided</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>com.google.auto.value</groupId>
63+
<artifactId>auto-value-annotations</artifactId>
64+
<version>1.9</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>com.google.code.findbugs</groupId>
69+
<artifactId>jsr305</artifactId> <!-- @Nullable annotations -->
70+
<version>3.0.2</version>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>com.google.guava</groupId>
75+
<artifactId>guava</artifactId>
76+
<version>31.0.1-jre</version>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>joda-time</groupId>
81+
<artifactId>joda-time</artifactId>
82+
<version>2.10.13</version>
83+
</dependency>
84+
85+
<!-- Test Dependencies -->
86+
<dependency>
87+
<groupId>junit</groupId>
88+
<artifactId>junit</artifactId>
89+
<version>4.13.2</version>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.mockito</groupId>
94+
<artifactId>mockito-all</artifactId>
95+
<version>1.10.19</version>
96+
<scope>test</scope>
97+
</dependency>
98+
99+
<dependency>
100+
<groupId>com.google.appengine</groupId>
101+
<artifactId>appengine-testing</artifactId>
102+
<version>2.0.4</version>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.google.appengine</groupId>
107+
<artifactId>appengine-api-stubs</artifactId>
108+
<version>2.0.4</version>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>com.google.appengine</groupId>
113+
<artifactId>appengine-tools-sdk</artifactId>
114+
<version>2.0.4</version>
115+
<scope>test</scope>
116+
</dependency>
117+
<dependency>
118+
<groupId>com.google.truth</groupId>
119+
<artifactId>truth</artifactId>
120+
<version>1.1.3</version>
121+
<scope>test</scope>
122+
</dependency>
123+
</dependencies>
124+
125+
<build>
126+
<!-- for hot reload of the web application -->
127+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
128+
<plugins>
129+
<plugin>
130+
<artifactId>maven-war-plugin</artifactId>
131+
<version>3.3.1</version> <!-- Needed for JDK17.-->
132+
<executions>
133+
<execution>
134+
<id>default-war</id>
135+
<phase>package</phase>
136+
<goals>
137+
<goal>war</goal>
138+
</goals>
139+
</execution>
140+
</executions>
141+
</plugin>
142+
<plugin>
143+
<groupId>com.google.cloud.tools</groupId>
144+
<artifactId>appengine-maven-plugin</artifactId>
145+
<version>2.4.1</version>
146+
<configuration>
147+
<projectId>GCLOUD_CONFIG</projectId>
148+
<version>GCLOUD_CONFIG</version>
149+
<gcloudMode>beta</gcloudMode>
150+
<deploy.promote>true</deploy.promote>
151+
<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
152+
</configuration>
153+
</plugin>
154+
155+
<plugin>
156+
<artifactId>maven-compiler-plugin</artifactId>
157+
<version>3.8.1</version>
158+
<configuration>
159+
<annotationProcessorPaths>
160+
<annotationProcessorPath>
161+
<groupId>com.google.auto.value</groupId>
162+
<artifactId>auto-value</artifactId>
163+
<version>1.9</version>
164+
</annotationProcessorPath>
165+
</annotationProcessorPaths>
166+
</configuration>
167+
</plugin>
168+
<plugin>
169+
<groupId>org.eclipse.jetty</groupId>
170+
<artifactId>jetty-maven-plugin</artifactId>
171+
<version>9.4.44.v20210927</version>
172+
</plugin>
173+
</plugins>
174+
</build>
175+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../appengine-java8/datastore/src/main/java/com/example/appengine/AbstractGuestbook.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../appengine-java8/datastore/src/main/java/com/example/appengine/AbstractGuestbookServlet.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../appengine-java8/datastore/src/main/java/com/example/appengine/Greeting.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../appengine-java8/datastore/src/main/java/com/example/appengine/Guestbook.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../../../../appengine-java8/datastore/src/main/java/com/example/appengine/GuestbookServlet.java

0 commit comments

Comments
 (0)