Skip to content

Commit 96445ac

Browse files
author
Les Vogel
committed
Initial commit of appengine-standard-java8
1 parent 967a706 commit 96445ac

11 files changed

Lines changed: 574 additions & 1 deletion

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
HelloWorld for App Engine Standard (Java 8)
2+
============================
3+
4+
This sample demonstrates how to deploy an application on Google App Engine.
5+
6+
See the [Google App Engine standard environment documentation][ae-docs] for more
7+
detailed instructions.
8+
9+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
10+
11+
12+
* [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
13+
* [Maven](https://maven.apache.org/download.cgi) (at least 3.5)
14+
* [Gradle](https://gradle.org/gradle-download/) (optional)
15+
* [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud)
16+
17+
## Setup
18+
19+
gcloud init
20+
gcloud beta auth application-default login
21+
22+
## Maven
23+
### Running locally
24+
25+
mvn appengine:run
26+
27+
### Deploying
28+
29+
mvn appengine:deploy
30+
31+
## Gradle
32+
### Running locally
33+
34+
gradle appengineRun
35+
36+
If you do not have gradle installed, you can run using `./gradlew appengineRun`.
37+
38+
### Deploying
39+
40+
gradle appengineDeploy
41+
42+
If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`.
43+
44+
## Testing
45+
46+
mvn verify
47+
48+
or
49+
50+
gradle test
51+
52+
As you add / modify the source code (`src/main/java/...`) it's very useful to add [unit testing](https://cloud.google.com/appengine/docs/java/tools/localunittesting)
53+
to (`src/main/test/...`). The following resources are quite useful:
54+
55+
* [Junit4](http://junit.org/junit4/)
56+
* [Mockito](http://mockito.org/)
57+
* [Truth](http://google.github.io/truth/)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2017 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// [START gradle]
15+
buildscript { // Configuration for building
16+
repositories {
17+
jcenter() // Bintray's repository - a fast Maven Central mirror & more
18+
mavenCentral()
19+
}
20+
dependencies {
21+
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' // latest App Engine Gradle tasks
22+
}
23+
}
24+
25+
repositories { // repositories for Jar's you access in your code
26+
maven {
27+
url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
28+
}
29+
mavenCentral()
30+
jcenter()
31+
}
32+
33+
apply plugin: 'java' // standard Java tasks
34+
apply plugin: 'war' // standard Web Archive plugin
35+
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
36+
37+
dependencies {
38+
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
39+
providedCompile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
40+
compile 'jstl:jstl:1.2'
41+
42+
// Add your dependencies here.
43+
// compile 'com.google.cloud:google-cloud:+' // Latest Cloud API's http://googlecloudplatform.github.io/google-cloud-java
44+
45+
testCompile 'junit:junit:4.12'
46+
testCompile 'com.google.truth:truth:0.30'
47+
testCompile 'org.mockito:mockito-all:1.10.19'
48+
49+
testCompile 'com.google.appengine:appengine-testing:+'
50+
testCompile 'com.google.appengine:appengine-api-stubs:+'
51+
testCompile 'com.google.appengine:appengine-tools-sdk:+'
52+
}
53+
54+
// Always run unit tests
55+
appengineDeploy.dependsOn test
56+
appengineStage.dependsOn test
57+
58+
// [START model]
59+
appengine { // App Engine tasks configuration
60+
deploy { // deploy configuration
61+
62+
}
63+
}
64+
65+
test {
66+
useJUnit()
67+
testLogging.showStandardStreams = true
68+
beforeTest { descriptor ->
69+
logger.lifecycle("test: " + descriptor + " Running")
70+
}
71+
72+
onOutput { descriptor, event ->
73+
logger.lifecycle("test: " + descriptor + ": " + event.message )
74+
}
75+
afterTest { descriptor, result ->
76+
logger.lifecycle("test: " + descriptor + ": " + result )
77+
}
78+
}
79+
// [END model]
80+
81+
group = "com.example.appengine_standard_java8" // Generated output GroupId
82+
version = "1.0-SNAPSHOT" // Version in generated output
83+
84+
sourceCompatibility = 1.8 // App Engine Flexible uses Java 8
85+
targetCompatibility = 1.8 // App Engine Flexible uses Java 8
86+
// [END gradle]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>helloworld_java8_GAE_standard</artifactId>
7+
<groupId>com.example.appengine_standard_java8</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>helloworld</artifactId>
13+
14+
15+
</project>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2017 Google Inc.
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+
19+
<modelVersion>4.0.0</modelVersion>
20+
<packaging>pom</packaging>
21+
<version>1.0-SNAPSHOT</version>
22+
<modules>
23+
<module>helloworld</module>
24+
</modules>
25+
26+
<groupId>com.example.appengine_standard_java8</groupId>
27+
<artifactId>helloworld_java8_GAE_standard</artifactId>
28+
29+
<parent> <!-- Get parameters and allow bulk testing -->
30+
<artifactId>getting-started-java</artifactId>
31+
<groupId>com.example</groupId>
32+
<version>1.0.0</version>
33+
<relativePath>../..</relativePath>
34+
</parent>
35+
36+
<properties>
37+
<appengine.version>1.9.52</appengine.version>
38+
<appengine.maven.plugin>1.3.1</appengine.maven.plugin>
39+
40+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
41+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
42+
<maven.compiler.source>1.8</maven.compiler.source>
43+
<maven.compiler.target>1.8</maven.compiler.target>
44+
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
45+
<archiveClasses>true</archiveClasses>
46+
<failOnMissingWebXml>false</failOnMissingWebXml>
47+
</properties>
48+
49+
<prerequisites>
50+
<maven>3.5</maven>
51+
</prerequisites>
52+
53+
<dependencies>
54+
<!-- Compile/runtime dependencies -->
55+
<dependency>
56+
<groupId>com.google.appengine</groupId>
57+
<artifactId>appengine-api-1.0-sdk</artifactId>
58+
<version>${appengine.version}</version>
59+
</dependency>
60+
<!-- [START servlet] -->
61+
<dependency>
62+
<groupId>javax.servlet</groupId>
63+
<artifactId>javax.servlet-api</artifactId>
64+
<version>3.1.0</version>
65+
<type>jar</type>
66+
<scope>provided</scope>
67+
</dependency>
68+
<!-- [END servlet] -->
69+
<dependency>
70+
<groupId>jstl</groupId>
71+
<artifactId>jstl</artifactId>
72+
<version>1.2</version>
73+
</dependency>
74+
75+
<!-- Test Dependencies -->
76+
<dependency>
77+
<groupId>com.google.appengine</groupId>
78+
<artifactId>appengine-testing</artifactId>
79+
<version>${appengine.version}</version>
80+
<scope>test</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.google.appengine</groupId>
84+
<artifactId>appengine-api-stubs</artifactId>
85+
<version>${appengine.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>com.google.appengine</groupId>
91+
<artifactId>appengine-tools-sdk</artifactId>
92+
<version>${appengine.version}</version>
93+
<scope>test</scope>
94+
</dependency>
95+
96+
<dependency>
97+
<groupId>com.google.truth</groupId>
98+
<artifactId>truth</artifactId>
99+
<version>0.32</version>
100+
<scope>test</scope>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>junit</groupId>
105+
<artifactId>junit</artifactId>
106+
<version>4.12</version>
107+
<scope>test</scope>
108+
</dependency>
109+
<dependency>
110+
<groupId>org.mockito</groupId>
111+
<artifactId>mockito-all</artifactId>
112+
<version>2.0.2-beta</version>
113+
<scope>test</scope>
114+
</dependency>
115+
</dependencies>
116+
117+
<build>
118+
<!-- for hot reload of the web application-->
119+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
120+
<plugins>
121+
<plugin>
122+
<groupId>org.codehaus.mojo</groupId>
123+
<artifactId>versions-maven-plugin</artifactId>
124+
<version>2.3</version>
125+
<executions>
126+
<execution>
127+
<phase>compile</phase>
128+
<goals>
129+
<goal>display-dependency-updates</goal>
130+
<goal>display-plugin-updates</goal>
131+
</goals>
132+
</execution>
133+
</executions>
134+
</plugin>
135+
136+
<plugin>
137+
<groupId>org.apache.maven.plugins</groupId>
138+
<artifactId>maven-war-plugin</artifactId>
139+
<version>2.6</version> <!-- required for Eclipse Mars -->
140+
<configuration>
141+
<archiveClasses>true</archiveClasses>
142+
<webResources>
143+
<!-- in order to interpolate version from pom into appengine-web.xml -->
144+
<resource>
145+
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
146+
<filtering>true</filtering>
147+
<targetPath>WEB-INF</targetPath>
148+
</resource>
149+
</webResources>
150+
</configuration>
151+
</plugin>
152+
153+
<!-- [START cloudplugin] -->
154+
<plugin>
155+
<groupId>com.google.cloud.tools</groupId>
156+
<artifactId>appengine-maven-plugin</artifactId>
157+
<version>${appengine.maven.plugin}</version>
158+
<configuration>
159+
</configuration>
160+
</plugin>
161+
<!-- [END cloudplugin] -->
162+
</plugins>
163+
</build>
164+
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.gaejava8standard;
18+
19+
// [START example]
20+
import java.io.IOException;
21+
22+
import javax.servlet.annotation.WebServlet;
23+
import javax.servlet.http.HttpServlet;
24+
import javax.servlet.http.HttpServletRequest;
25+
import javax.servlet.http.HttpServletResponse;
26+
27+
@WebServlet(name = "HelloAppEngine", value = "/hello")
28+
public class HelloAppEngine extends HttpServlet {
29+
30+
@Override
31+
public void doGet(HttpServletRequest request, HttpServletResponse response)
32+
throws IOException {
33+
34+
response.setContentType("text/plain");
35+
response.getWriter().println("Hello App Engine - Standard using Java 8!");
36+
37+
}
38+
}
39+
// [END example]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you
5+
* may not use this file except in compliance with the License. You may
6+
* obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
package com.example.gaejava8standard;
18+
19+
// [START example]
20+
/**
21+
* Generate some simple information.
22+
*/
23+
public class HelloInfo {
24+
25+
public static String getInfo() {
26+
return "Version: " + System.getProperty("java.version")
27+
+ " OS: " + System.getProperty("os.name")
28+
+ " User: " + System.getProperty("user.name");
29+
}
30+
}
31+
// [END example]

0 commit comments

Comments
 (0)