Skip to content

Commit edc690c

Browse files
committed
Updated rundoc template
1 parent 6dd34f3 commit edc690c

File tree

1 file changed

+10
-41
lines changed

1 file changed

+10
-41
lines changed

docs/java-getting-started.md

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Once dependencies are installed, you can run your app locally.
272272
Start your application locally with the `heroku local` CLI command (make sure you've already run `mvn clean install`):
273273

274274
```term
275-
:::>> background.start("heroku local web", name: "local1", wait: "Started Main in", timeout: 20)
275+
:::>> background.start("heroku local web", name: "local1", wait: "Tomcat started", timeout: 30)
276276
:::-- background.stop(name: "local1")
277277
```
278278

@@ -340,7 +340,8 @@ Now test your changes locally:
340340

341341
```term
342342
:::>- $ mvn clean install
343-
$ heroku local web
343+
:::>> background.start("heroku local web", name: "local2", wait: "Tomcat started", timeout: 30)
344+
:::-- background.stop(name: "local2")
344345
```
345346

346347
Visiting your application's `/hello` path at [http://localhost:5000/hello](http://localhost:5000/hello), you should see some great scientific conversions displayed:
@@ -379,7 +380,7 @@ At runtime, config vars are exposed to your app as environment variables. For ex
379380

380381
```java
381382
:::-- sed -e '56,68d' src/main/java/com/example/Main.java
382-
:::>> file.write src/main/java/com/example/Main.java#56
383+
:::>> file.append("src/main/java/com/example/Main.java#56")
383384
@RequestMapping("/hello")
384385
String hello(Map<String, Object> model) {
385386
RelativisticModel.select();
@@ -425,7 +426,9 @@ Deploy your updated application to Heroku to see this in action.
425426
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:
426427

427428
```term
428-
:::>> $ heroku run java -version
429+
:::-- $ heroku run java -version
430+
:::-- | grep -vq starting
431+
:::-> | grep -vq connecting
429432
```
430433

431434
If you receive an error, `Error connecting to process`, then you might need to [configure your firewall](one-off-dynos#timeout-awaiting-process).
@@ -496,45 +499,11 @@ The example app you deployed already has database functionality, which you can r
496499
The code to access the database is straightforward. Here's the method to insert values into a table called `tick`:
497500

498501
```java
499-
@Value("${spring.datasource.url}")
500-
private String dbUrl;
501-
502-
@Autowired
503-
private DataSource dataSource;
502+
:::-- sed -e '45,49p' src/main/java/com/example/Main.java
504503

505504
...
506505

507-
@RequestMapping("/db")
508-
String db(Map<String, Object> model) {
509-
try (Connection connection = dataSource.getConnection()) {
510-
Statement stmt = connection.createStatement();
511-
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)");
512-
stmt.executeUpdate("INSERT INTO ticks VALUES (now())");
513-
ResultSet rs = stmt.executeQuery("SELECT tick FROM ticks");
514-
515-
ArrayList<String> output = new ArrayList<String>();
516-
while (rs.next()) {
517-
output.add("Read from DB: " + rs.getTimestamp("tick"));
518-
}
519-
520-
model.put("records", output);
521-
return "db";
522-
} catch (Exception e) {
523-
model.put("message", e.getMessage());
524-
return "error";
525-
}
526-
}
527-
528-
@Bean
529-
public DataSource dataSource() throws SQLException {
530-
if (dbUrl == null || dbUrl.isEmpty()) {
531-
return new HikariDataSource();
532-
} else {
533-
HikariConfig config = new HikariConfig();
534-
config.setJdbcUrl(dbUrl);
535-
return new HikariDataSource(config);
536-
}
537-
}
506+
:::-- sed -e '66,109p' src/main/java/com/example/Main.java
538507
```
539508

540509
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.
@@ -592,4 +561,4 @@ Here's some recommended reading to continue your Heroku journey:
592561

593562
* [How Heroku Works](how-heroku-works) provides a technical overview of the concepts you’ll encounter while writing, configuring, deploying, and running apps.
594563
* The [Java category](/categories/java-support) provides more in-depth information on developing and deploying Java apps.
595-
* The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments.
564+
* The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments.

0 commit comments

Comments
 (0)