Skip to content

Commit d4a4ec4

Browse files
authored
Move helloworld samples from getting-started-java (GoogleCloudPlatform#3010)
Fixes #issue > It's a good idea to open an issue first for discussion. - [ ] I have followed [Sample Format Guide](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/SAMPLE_FORMAT.md) - [ ] `pom.xml` parent set to latest `shared-configuration` - [ ] Appropriate changes to README are included in PR - [ ] API's need to be enabled to test (tell us) - [ ] Environment Variables need to be set (ask us to set them) - [ ] Tests pass (`mvn -P lint clean verify`) * (Note- `Checkstyle` passing is required; `Spotbugs`, `ErrorProne`, `PMD`, etc. `ERROR`'s are advisory only) - [ ] Please **merge** this PR for me once it is approved.
1 parent 2340b7e commit d4a4ec4

File tree

31 files changed

+1945
-0
lines changed

31 files changed

+1945
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
• Download and initialize the [Cloud SDK](https://cloud.google.com/sdk/)
20+
21+
```
22+
gcloud init
23+
```
24+
25+
* Create an App Engine app within the current Google Cloud Project
26+
27+
```
28+
gcloud app create
29+
```
30+
31+
* In the `pom.xml`, update the [App Engine Maven Plugin](https://cloud.google.com/appengine/docs/standard/java/tools/maven-reference)
32+
with your Google Cloud Project Id:
33+
34+
```
35+
<plugin>
36+
<groupId>com.google.cloud.tools</groupId>
37+
<artifactId>appengine-maven-plugin</artifactId>
38+
<version>2.2.0</version>
39+
<configuration>
40+
<projectId>myProjectId</projectId>
41+
<version>GCLOUD_CONFIG</version>
42+
</configuration>
43+
</plugin>
44+
```
45+
**Note:** `GCLOUD_CONFIG` is a special version for autogenerating an App Engine
46+
version. Change this field to specify a specific version name.
47+
48+
## Maven
49+
### Running locally
50+
51+
mvn package appengine:run
52+
53+
To use vist: http://localhost:8080/
54+
55+
### Deploying
56+
57+
mvn package appengine:deploy
58+
59+
To use vist: https://YOUR-PROJECT-ID.appspot.com
60+
61+
## Gradle
62+
### Running locally
63+
64+
gradle appengineRun
65+
66+
If you do not have gradle installed, you can run using `./gradlew appengineRun`.
67+
68+
To use vist: http://localhost:8080/
69+
70+
### Deploying
71+
72+
gradle appengineDeploy
73+
74+
If you do not have gradle installed, you can deploy using `./gradlew appengineDeploy`.
75+
76+
To use vist: https://YOUR-PROJECT-ID.appspot.com
77+
78+
## Testing
79+
80+
mvn verify
81+
82+
or
83+
84+
gradle test
85+
86+
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)
87+
to (`src/main/test/...`). The following resources are quite useful:
88+
89+
* [Junit4](http://junit.org/junit4/)
90+
* [Mockito](http://mockito.org/)
91+
* [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:2.2.0' // If a newer version is available, use it
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+
compile 'com.google.appengine:appengine-api-1.0-sdk:+' // Latest App Engine Api's
39+
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
40+
41+
compile 'jstl:jstl:1.2'
42+
43+
// Add your dependencies here.
44+
// compile 'com.google.cloud:google-cloud:+' // Latest Cloud API's http://googlecloudplatform.github.io/google-cloud-java
45+
46+
testCompile 'junit:junit:4.12'
47+
testCompile 'com.google.truth:truth:0.33'
48+
testCompile 'org.mockito:mockito-all:1.10.19'
49+
50+
testCompile 'com.google.appengine:appengine-testing:+'
51+
testCompile 'com.google.appengine:appengine-api-stubs:+'
52+
testCompile 'com.google.appengine:appengine-tools-sdk:+'
53+
}
54+
55+
// Always run unit tests
56+
appengineDeploy.dependsOn test
57+
appengineStage.dependsOn test
58+
59+
appengine { // App Engine tasks configuration
60+
deploy { // deploy configuration
61+
projectId = System.getenv('GOOGLE_CLOUD_PROJECT')
62+
version = '1'
63+
}
64+
}
65+
66+
test {
67+
useJUnit()
68+
testLogging.showStandardStreams = true
69+
beforeTest { descriptor ->
70+
logger.lifecycle("test: " + descriptor + " Running")
71+
}
72+
73+
onOutput { descriptor, event ->
74+
logger.lifecycle("test: " + descriptor + ": " + event.message )
75+
}
76+
afterTest { descriptor, result ->
77+
logger.lifecycle("test: " + descriptor + ": " + result )
78+
}
79+
}
80+
81+
group = "com.example.appenginej8" // 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Jun 13 16:53:48 PDT 2017
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip

appengine-java8/helloworld/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)