You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You now have a functioning Git repository that contains a simple Java application. The application includes a `pom.xml` file, which is used by Java's dependency manager, Maven.
@@ -132,7 +135,8 @@ By default, Heroku generates a random name (in this case `warm-eyrie-9006`) for
132
135
Now deploy your code:
133
136
134
137
```term
135
-
:::>> $ git push heroku master
138
+
:::>- $ git push heroku master
139
+
:::-> | $ (head -6; echo "..."; tail -18)
136
140
```
137
141
138
142
The application is now deployed. Ensure that at least one instance of the app is running:
@@ -154,23 +158,12 @@ Heroku aggregates all of the output streams from both your app and the platform'
154
158
View information about your running app using the `heroku logs --tail` command:
155
159
156
160
```term
157
-
$ heroku logs --tail
158
-
2017-04-20T15:06:14.198559+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=43161 -jar target/java-getting-started-1.0.jar`
159
-
2017-04-20T15:06:16.478043+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
160
-
2017-04-20T15:06:16.484066+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2017-04-20T15:06:33.472964+00:00 app[web.1]: 2017-04-20 15:06:33.472 INFO 4 --- [ main] com.example.Main : Started Main in 15.345 seconds (JVM running for 16.989)
170
-
2017-04-20T15:06:33.778990+00:00 heroku[web.1]: State changed from starting to up
171
-
```
172
-
173
-
Visit your application in the browser again to generate another log message.
Visit your application in the browser again to generate another log message.
174
167
175
168
Press `CTRL+C` to stop streaming logs.
176
169
@@ -180,7 +173,7 @@ Heroku apps use a special plaintext file called the [Procfile](procfile) to expl
180
173
181
174
The `Procfile` in the example app you deployed looks like this:
182
175
183
-
```
176
+
```yaml
184
177
:::-> $ cat Procfile
185
178
```
186
179
@@ -190,7 +183,7 @@ Procfiles can contain additional process types. For example, you might declare o
190
183
191
184
<h2data-next-message="I know how to scale my app">Scale the app</h2>
192
185
193
-
Right now, your app is running on a single web [dyno](dynos). A dyno is a lightweight Linux container that runs the command specified in your `Procfile`.
186
+
Right now, your app is running on a single web [dyno](dynos). A dyno is a lightweight Linux container that runs the command specified in your `Procfile`.
194
187
195
188
You can check how many dynos are running using the `heroku ps` command:
196
189
@@ -200,7 +193,7 @@ You can check how many dynos are running using the `heroku ps` command:
200
193
201
194
By default, your app is deployed on a free dyno. Free dynos sleep after thirty minutes of inactivity (i.e., if they don't receive any traffic). This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally.
202
195
203
-
Free dynos consume from a monthly, account-level quota of [free dyno hours](free-dyno-hours). As long as the quota is not exhausted, your free apps can continue to run.
196
+
Free dynos consume from a monthly, account-level quota of [free dyno hours](free-dyno-hours). As long as the quota is not exhausted, your free apps can continue to run.
204
197
205
198
To avoid dyno sleeping, you can upgrade to a hobby or professional dyno type as described in [Dyno Types](dyno-types). For example, if you migrate your app to a professional dyno, you can easily scale it by running a command telling Heroku to spin up a specific number of dynos, each running your web process type.
206
199
@@ -212,15 +205,15 @@ Scale the number of web dynos to zero:
212
205
:::>- $ heroku ps:scale web=0
213
206
```
214
207
215
-
Access the app again by refreshing your browser or running `heroku open`. You will get an error message because your app no longer has any web dynos available to serve requests.
208
+
Access the app again by refreshing your browser or running `heroku open`. You will get an error message because your app no longer has any web dynos available to serve requests.
216
209
217
210
Scale it up again:
218
211
219
212
```term
220
213
:::>- $ heroku ps:scale web=1
221
214
```
222
215
223
-
To prevent abuse, scaling a non-free application to more than one dyno requires [account verification](account-verification).
216
+
To prevent abuse, scaling a non-free application to more than one dyno requires [account verification](account-verification).
224
217
225
218
<h2data-next-message="I've installed the app dependencies locally">Declare app dependencies</h2>
226
219
@@ -243,12 +236,13 @@ Another file, `system.properties`, indicates the version of Java to use (Heroku
243
236
Run `mvn clean install` in your local directory to install the dependencies, preparing your system for running the app locally. Note that this app requires Java 8, but you can push your own apps using a different version of Java.
244
237
245
238
```term
246
-
:::>> $ mvn clean install
239
+
:::>- $ mvn clean install
240
+
:::-> | $ (echo "..."; tail -7)
247
241
```
248
242
249
243
If you do not have Maven installed, or get an error like `'mvn' is not recognized as an internal or external command`, then you can use the wrapper command instead by running `mvnw clean install` on Windows or `./mvnw clean install` on Mac and Linux. This both installs Maven and runs the Maven command.
250
244
251
-
The Maven process compiles and build a JAR, with dependencies, placing it into your application's `target` directory. This process is accomplished with the `spring-boot-maven-plugin` in the `pom.xml`.
245
+
The Maven process compiles and build a JAR, with dependencies, placing it into your application's `target` directory. This process is accomplished with the `spring-boot-maven-plugin` in the `pom.xml`.
252
246
253
247
If you aren't using Spring in your app, you can accomplish this with the following plugin configuration in the `pom.xml` file.
254
248
@@ -272,13 +266,14 @@ Once dependencies are installed, you can run your app locally.
272
266
Start your application locally with the `heroku local` CLI command (make sure you've already run `mvn clean install`):
@@ -378,8 +374,11 @@ Heroku lets you externalize your app's configuration by storing data such as enc
378
374
379
375
At runtime, config vars are exposed to your app as environment variables. For example, modify `src/main/java/com/example/Main.java` so that the method obtains an energy value from the `ENERGY` environment variable:
380
376
377
+
```
378
+
:::-- $ sed -e '56,68d' src/main/java/com/example/Main.java
379
+
```
380
+
381
381
```java
382
-
:::-- sed -e '56,68d' src/main/java/com/example/Main.java
@@ -426,9 +425,8 @@ Deploy your updated application to Heroku to see this in action.
426
425
The `heroku run` command lets you run maintenance and administrative tasks on your app in a [one-off dyno](one-off-dynos). It can also lets you launch a REPL process attached to your local terminal for experimenting in your app's environment, or code that you deployed with your application:
427
426
428
427
```term
429
-
:::-- $ heroku run java -version
430
-
:::-- | grep -vq starting
431
-
:::-> | grep -vq connecting
428
+
:::>- $ heroku run java -version
429
+
:::-> | $ tail -4
432
430
```
433
431
434
432
If you receive an error, `Error connecting to process`, then you might need to [configure your firewall](one-off-dynos#timeout-awaiting-process).
@@ -499,11 +497,7 @@ The example app you deployed already has database functionality, which you can r
499
497
The code to access the database is straightforward. Here's the method to insert values into a table called `tick`:
500
498
501
499
```java
502
-
:::-- sed -e '45,49p' src/main/java/com/example/Main.java
503
-
504
-
...
505
-
506
-
:::-- sed -e '66,109p' src/main/java/com/example/Main.java
500
+
:::-> $ sed -n '45,50p;78,109p' src/main/java/com/example/Main.java
507
501
```
508
502
509
503
This ensures that when you access your app using the `/db` route, a new row is added to the `tick` table, and all rows are then returned so that they can be rendered in the output.
@@ -529,22 +523,18 @@ Assuming that you have [Postgres installed locally](heroku-postgresql#local-setu
0 commit comments