From 437af1010f3203e34024cccf83a674c811fc2e31 Mon Sep 17 00:00:00 2001 From: thomaswoehlke Date: Sat, 4 Apr 2020 18:25:22 +0200 Subject: [PATCH 1/2] setup localdev on win10 --- .../db-createdb-and-user-linux.sql | 45 +++++++++++++++++++ .../db-createdb-and-user-win10.sql | 45 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 etc/development/db-createdb-and-user-linux.sql create mode 100644 etc/development/db-createdb-and-user-win10.sql diff --git a/etc/development/db-createdb-and-user-linux.sql b/etc/development/db-createdb-and-user-linux.sql new file mode 100644 index 00000000..e0aedde1 --- /dev/null +++ b/etc/development/db-createdb-and-user-linux.sql @@ -0,0 +1,45 @@ + +CREATE USER simpleworklist WITH PASSWORD 'simpleworklistpwd' SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION; + +GRANT pg_monitor TO simpleworklist; +GRANT pg_read_all_settings TO simpleworklist; +GRANT pg_read_all_stats TO simpleworklist; +GRANT pg_signal_backend TO simpleworklist; +GRANT pg_stat_scan_tables TO simpleworklist; + + +CREATE DATABASE simpleworklist WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_default WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_default TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_branch_master WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_branch_master TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_testing WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_testing TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_heroku WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; + +GRANT ALL ON DATABASE simpleworklist_heroku TO simpleworklist WITH GRANT OPTION; + + +GRANT ALL ON DATABASE artifactory TO artifactory WITH GRANT OPTION; + + + + + diff --git a/etc/development/db-createdb-and-user-win10.sql b/etc/development/db-createdb-and-user-win10.sql new file mode 100644 index 00000000..b90462d0 --- /dev/null +++ b/etc/development/db-createdb-and-user-win10.sql @@ -0,0 +1,45 @@ + +CREATE USER simpleworklist WITH PASSWORD 'simpleworklistpwd' SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION; + +GRANT pg_monitor TO simpleworklist; +GRANT pg_read_all_settings TO simpleworklist; +GRANT pg_read_all_stats TO simpleworklist; +GRANT pg_signal_backend TO simpleworklist; +GRANT pg_stat_scan_tables TO simpleworklist; + + +CREATE DATABASE simpleworklist WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_default WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_default TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_branch_master WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_branch_master TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_testing WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_testing TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; + +CREATE DATABASE simpleworklist_heroku WITH OWNER simpleworklist TEMPLATE 'template0' ENCODING 'UTF8' LC_COLLATE 'de-DE' LC_CTYPE 'de-DE'; + +GRANT ALL ON DATABASE simpleworklist_heroku TO simpleworklist WITH GRANT OPTION; + + +GRANT ALL ON DATABASE artifactory TO artifactory WITH GRANT OPTION; + + + + + From 46dd8f0b557da45b0e4087774d6d177a1739d988 Mon Sep 17 00:00:00 2001 From: thomaswoehlke Date: Sat, 4 Apr 2020 19:36:43 +0200 Subject: [PATCH 2/2] setup localdev on win10 --- .gitignore | 2 +- .../archiv/deploying-spring-boot-apps.md | 254 -------- .../archiv/java-getting-started.md | 554 ------------------ setenv-sample.cmd | 10 + 4 files changed, 11 insertions(+), 809 deletions(-) delete mode 100644 etc/development/archiv/deploying-spring-boot-apps.md delete mode 100644 etc/development/archiv/java-getting-started.md create mode 100644 setenv-sample.cmd diff --git a/.gitignore b/.gitignore index 0f6f5fb9..ca7505a9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,5 @@ docs/tmp/ docs/java-getting-started/ docs/deploying-spring-boot-apps/ setenv.sh - +setenv.cmd /etc/pom.xml diff --git a/etc/development/archiv/deploying-spring-boot-apps.md b/etc/development/archiv/deploying-spring-boot-apps.md deleted file mode 100644 index 91a0d368..00000000 --- a/etc/development/archiv/deploying-spring-boot-apps.md +++ /dev/null @@ -1,254 +0,0 @@ -``` -:::-- rundoc -email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami` - -Rundoc.configure do |config| - config.project_root = "deploying-spring-boot-apps" - config.filter_sensitive(email => "developer@example.com") -end -``` - - -The Spring Boot model of deploying standalone applications is a great -fit for Heroku. You can use either Maven or Gradle to deploy a Spring application on Heroku, but for this guide we'll assume that you're using Maven and have [Maven 3](http://maven.apache.org/download.html) installed on your machine. - -To begin, create a [free Heroku account](https://signup.heroku.com/). -Then download and install the Heroku CLI. - -Download the Heroku CLI - -Once installed, you can use the `heroku` command from the terminal to log in using the email address and password you used when creating your Heroku account: - -```term -$ heroku login -heroku: Press any key to open up the browser to login or q to exit - › Warning: If browser does not open, visit - › https://cli-auth.heroku.com/auth/browser/*** -heroku: Waiting for login... -Logging in... done -Logged in as me@example.com -``` - -To check that your key was added, run `heroku keys`. If your key isn’t there, you -can add it manually by running `heroku keys:add`. For more information about SSH -keys, see [Managing Your SSH Keys](https://devcenter.heroku.com/articles/keys). - -## Creating a Spring Boot app - -To create a new Spring Boot application, first install the Spring Boot CLI as described in the [Spring Boot documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html). This will add a `spring` command to your path. - ->note ->You can also start with a working [sample app](https://github.com/heroku/java-getting-started) if you'd prefer. - -Use the CLI to create a new application by running this command: - -```term -:::>- $ spring init --dependencies=web demo -``` - -Then move into the application directory: - -```term -:::>- $ cd demo -``` - -The application does not have any custom logic by default -- it's just an empty template. To add some behavior, open the `src/main/java/com/example/demo/DemoApplication.java` file and put the following code in it: - -```java -:::>> file.write src/main/java/com/example/demo/DemoApplication.java -package com.example.demo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.*; -import org.springframework.stereotype.*; - -@Controller -@SpringBootApplication -public class DemoApplication { - - @RequestMapping("/") - @ResponseBody - String home() { - return "Hello World!"; - } - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } -} -``` - -This creates a simple request mapping that displayed "Hello World!" in the browser. You could run the application locally to confirm this, but we'll jump straight to running it on Heroku. - -## Preparing a Spring Boot app for Heroku - -Before you can deploy the app to Heroku, you'll need to create a Git repository for the application and add all of the code to it by running these commands: - -```term -:::>- $ git init -:::>- $ git add . -:::>- $ git commit -m "first commit" -``` - -You'll deploy the app by pushing this Git repo to Heroku. It's also possible to deploy using the [Heroku Maven plugin](deploying-java-applications-with-the-heroku-maven-plugin), but this guide will focus on using Git and the Heroku CLI. - -In order to deploy to Heroku, you'll first need to provision a new Heroku app. Run this command: - -```term -:::>> $ heroku create -``` - -This also creates a remote repository called `heroku` in -your local git repo. Heroku generates a random name (in this case `nameless-lake-8055`) -for your app. You can rename it later with the `heroku apps:rename` command. - -Now deploy your code: - -```term -:::>- $ git push heroku master -:::-> | $ (head -6; echo "..."; tail -18) -``` - -Heroku automatically detects the application as a Maven/Java app due to the presence of a `pom.xml` file. It installed Java 8 by default, but you can easily configure this with a `system.properties` file as described in the [Specifying a Java version](https://devcenter.heroku.com/articles/java-support#specifying-a-java-version) Dev Center article. It will run your app using the [default command](https://devcenter.heroku.com/articles/java-support#default-web-process-type). - -All that said, the application is now deployed. You can visit the app's URL by running this command: - -```term -:::>- $ heroku open -``` - -You'll see the "Hello World!" text in the browser. - -You can view the logs for the application by running this command: - -```term -:::>- background.start("heroku logs --tail", name: "tail", wait: "State changed from starting to up", timeout: 45) -:::-> | tail -10 -:::-- background.stop(name: "tail") -``` - -Reload your application in the browser, and you’ll see another log message generated for that request. Press `Control+C` to stop streaming the logs. - -To learn more about the basics of deploying a Maven-based Java application on Heroku, try following the [Getting Started with Java on Heroku](getting-started-with-java) guide. This guide covers many steps that are not specific to Spring Boot. - -The remainder of this article provides a cursory overview of some of the most common settings you'll need to adjust. - -## Connecting to a database - -You can attach a PostgreSQL database to your app by running the following command from the CLI: - -```term -:::>- $ heroku addons:create heroku-postgresql -``` - -If you prefer to use MySQL or another database vendor, check out [Add-ons Marketplace](https://elements.heroku.com/addons) to see what is available. - -Now you can list the configuration variables for your app to display the URL needed to connect to the database, DATABASE_URL: - -```term -:::>> $ heroku config -``` - -Heroku also provides a `pg` command that shows a lot more: - -```term -:::>> $ heroku pg -``` - -This indicates a hobby database (free) is running Postgres 9.3.3, with a single row of data. - -Once the database add-on has been created, Heroku will automatically populate the environment variables `SPRING_DATASOURCE_URL`, `SPRING_DATASOURCE_USERNAME`, and `SPRING_DATASOURCE_PASSWORD`. These environment variables should allow your Spring Boot application to connect to the database without any other configuration as long as you add a PostgreSQL JDBC driver to your dependencies like so: - -```xml -:::>> file.append("pom.xml#26") - - org.springframework.boot - spring-boot-starter-jdbc - - - org.postgresql - postgresql - -``` - -You can customize your application's database configuration in your `application.properties`. For example: - - -```properties -:::>> file.write src/main/resources/application.properties -spring.datasource.driverClassName=org.postgresql.Driver -spring.datasource.maxActive=10 -spring.datasource.maxIdle=5 -spring.datasource.minIdle=2 -spring.datasource.initialSize=5 -spring.datasource.removeAbandoned=true -``` - -Then you can then add a configuration bean to your app. - -```java -:::>> file.write src/main/java/demo/DatabaseConfig.java -package com.example.demo; - -import com.zaxxer.hikari.*; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.*; -import javax.sql.DataSource; - -@Configuration -public class DatabaseConfig { - - @Value("${spring.datasource.url}") - private String dbUrl; - - @Bean - public DataSource dataSource() { - HikariConfig config = new HikariConfig(); - config.setJdbcUrl(dbUrl); - return new HikariDataSource(config); - } -} -``` - -``` -:::-- $ git add . -:::-- $ git commit -m "database" -:::-- $ git push heroku master -:::-- $ cd .. -:::-- $ mv demo deploying-spring-boot-apps -``` - -For more information, see [Connecting to Relational Databases on Heroku with Java](articles/connecting-to-relational-databases-on-heroku-with-java). - -Now your application should be able to connect to the database. You can follow our guide on [Running Database Migrations for Java Apps](https://devcenter.heroku.com/articles/running-database-migrations-for-java-apps) to initialize the database. The [sample app](https://github.com/kissaten/spring-boot-heroku-demo) uses Liquibase. - -## Customizing the boot command - -You can override the default command used to run your app or define custom process types using a [`Procfile`](https://devcenter.heroku.com/articles/procfile). The correct command depends on what you need to do with your app. Common process types are used to [run a web process](https://devcenter.heroku.com/articles/java-support#default-web-process-type) or [run database migrations](https://devcenter.heroku.com/articles/running-database-migrations-for-java-apps). - -## Next steps - -For more complete examples of Spring Boot apps that run on Heroku see: - -* [Getting Started on Heroku with Java](articles/getting-started-with-java#introduction) -* [Spring Petclinic Demo for Heroku](https://github.com/kissaten/spring-petclinic) - -Heroku provides a wide range of features for Spring applications. You can provision -add-ons that introduce third-party cloud services like persistence, logging, monitoring and more. -The [add-on marketplace](https://elements.heroku.com/addons/#data-stores) has a large -number of data stores, from Redis and MongoDB providers, to Postgres and MySQL. - -You can read more about [How Heroku Works](https://devcenter.heroku.com/articles/how-heroku-works) -to get a technical overview of the concepts you’ll encounter while writing, configuring, deploying and running applications. -Then visit the [Java category on Dev Center](https://devcenter.heroku.com/categories/java-support) -to learn more about developing and deploying Spring applications. -If you experience any trouble with your application as you migrate to Heroku, reach out to any of our [Support channels](https://devcenter.heroku.com/articles/support-channels). - -For more information on deploying Spring apps, see the [Spring documentation](http://projects.spring.io/spring-boot/#quick-start) and the [Spring Boot documentation on deploy to Heroku](http://docs.spring.io/spring-boot/docs/current/reference/html/cloud-deployment.html#cloud-deployment-heroku). diff --git a/etc/development/archiv/java-getting-started.md b/etc/development/archiv/java-getting-started.md deleted file mode 100644 index c63ccdd0..00000000 --- a/etc/development/archiv/java-getting-started.md +++ /dev/null @@ -1,554 +0,0 @@ -``` -:::-- rundoc -email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami` - -Rundoc.configure do |config| - config.project_root = "java-getting-started" - config.filter_sensitive(email => "developer@example.com") -end -``` - - -

Introduction

- -This tutorial will have you deploying a Java app in minutes. - -Hang on for a few more minutes to learn how it all works, so you can make the most out of Heroku. - -The tutorial assumes that you already have: - -* A free Heroku account -* Java 8 installed -* Maven 3 installed - -If you'd prefer to use Gradle instead of Maven, please see the [Getting Started with Gradle on Heroku](getting-started-with-gradle-on-heroku) guide. - -

Set up

- ->callout ->The Heroku CLI requires **Git**, the popular version control system. If you don't already have Git installed, complete the following before proceeding: -> -> * Git installation -> * First-time Git setup - -In this step you'll install the Heroku Command Line Interface (CLI). You use the CLI to manage and scale your applications, provision add-ons, view your application logs, and run your application locally. - -Download and run the installer for your platform: - -
-
-
-
-
macOS
-

- Download the installer

-

Also available via Homebrew:

-
$ brew install heroku/brew/heroku
-
-
-
Windows
-

Download the appropriate installer for your Windows installation:

-

- 64-bit installer

-

32-bit installer

-
-
-
-
-
Ubuntu 16+
-

Run the following from your terminal:

-
$ sudo snap install heroku --classic
-

Snap is available on other Linux OS's as well. -

-
-
-
-
- -When installation completes, you can use the `heroku` command from your terminal. - -
On Windows, start the Command Prompt (cmd.exe) or Powershell to access the command shell.
- -Use the `heroku login` command to log in to the Heroku CLI: - -```term -$ heroku login -heroku: Press any key to open up the browser to login or q to exit - › Warning: If browser does not open, visit - › https://cli-auth.heroku.com/auth/browser/*** -heroku: Waiting for login... -Logging in... done -Logged in as me@example.com -``` - -This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, simply click the **Log in** button displayed on the page. - -This authentication is required for both the `heroku` and `git` commands to work correctly. - -Note that if you’re behind a firewall that requires use of a proxy to connect with external HTTP/HTTPS services, [you can set the `HTTP_PROXY` or `HTTPS_PROXY` environment variables](articles/using-the-cli#using-an-http-proxy) in your local development environment before running the `heroku` command. - -

Prepare the app

- -In this step, you will prepare a sample application that's ready to be deployed to Heroku. - ->callout ->If you are new to Heroku, it is recommended that you ->complete this tutorial using the Heroku-provided sample application. -> ->However, if you have your own existing application that you want to deploy ->instead, see this article ->to learn how to prepare it for Heroku deployment. - -To create a local copy of a sample app that you can deploy to Heroku, execute the following commands in your local command shell or terminal: - - -```term -:::>- $ git clone https://github.com/heroku/java-getting-started -:::>- $ cd java-getting-started -:::-- $ git fetch -:::-- $ git merge origin/master -``` - -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. - -

Deploy the app

- -In this step you'll deploy the sample app to Heroku. - -First, create an app on Heroku, which prepares Heroku to receive your source code: - -```term -:::>> $ heroku create -``` - -When you create an app, a Git remote (named `heroku`) is also created and associated with your local Git repository. - -By default, Heroku generates a random name (in this case `warm-eyrie-9006`) for your app. You can pass a parameter to specify your own app name. - -Now deploy your code: - -```term -:::>- $ git push heroku master -:::-> | $ (head -6; echo "..."; tail -18) -``` - -The application is now deployed. Ensure that at least one instance of the app is running: - -```term -:::>- $ heroku ps:scale web=1 -``` - -Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website like so: - -```term -:::>- $ heroku open -``` - -

View logs

- -Heroku aggregates all of the output streams from both your app and the platform's components into a single channel of time-ordered logs. - -View information about your running app using the `heroku logs --tail` command: - -```term -:::>- background.start("heroku logs --tail", name: "tail", wait: "State changed from starting to up", timeout: 45) -:::-> | tail -10 -:::-- background.stop(name: "tail") -``` - -Visit your application in the browser again to generate another log message. - -Press `CTRL+C` to stop streaming logs. - -

Define a Procfile

- -Heroku apps use a special plaintext file called the [Procfile](procfile) to explicitly declare what command should be executed to start your app. - -The `Procfile` in the example app you deployed looks like this: - -```yaml -:::-> $ cat Procfile -``` - -This declares a single process type, `web`, and the command needed to run it. The name `web` is important here. It declares that this process type will be attached to Heroku's [HTTP routing](http-routing) stack, and it will be able to receive web traffic. - -Procfiles can contain additional process types. For example, you might declare one for a background worker that processes items off of a queue. - -

Scale the app

- -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`. - -You can check how many dynos are running using the `heroku ps` command: - -```term -:::>> $ heroku ps -``` - -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. - -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. - -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. - -Scaling an application on Heroku is equivalent to changing the number of dynos that are running. - -Scale the number of web dynos to zero: - -```term -:::>- $ heroku ps:scale web=0 -``` - -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. - -Scale it up again: - -```term -:::>- $ heroku ps:scale web=1 -``` - -To prevent abuse, scaling a non-free application to more than one dyno requires [account verification](account-verification). - -

Declare app dependencies

- -Heroku automatically identifies an app as a Java app if it contains a `pom.xml` file in the root directory. You can create a `pom.xml` file for your own apps with the `mvn archetype:create` command. - -The demo app you deployed already has a `pom.xml` ([see it here](https://github.com/heroku/java-getting-started/blob/master/pom.xml)). Here's an excerpt: - -```xml -:::-> $ sed -n '27,35p' pom.xml -``` - -The `pom.xml` file specifies dependencies that should be installed with your application. When an app is deployed, Heroku reads this file and installs the dependencies by running `mvn clean install`. - -Another file, `system.properties`, indicates the version of Java to use (Heroku supports many [different versions](java-support#supported-java-versions)). The contents of this optional file are straightforward: - -``` -:::-> $ cat system.properties -``` - -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. - -```term -:::>- $ mvn clean install -:::-> | $ (echo "..."; tail -7) -``` - -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. - -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`. - -If you aren't using Spring in your app, you can accomplish this with the following plugin configuration in the `pom.xml` file. - -```xml - - maven-assembly-plugin - 3.0.0 - - - jar-with-dependencies - - helloworld - - -``` - -Once dependencies are installed, you can run your app locally. - -

Run the app locally

- -Start your application locally with the `heroku local` CLI command (make sure you've already run `mvn clean install`): - -```term -:::>- background.start("heroku local web", name: "local1", wait: "Tomcat started", timeout: 30) -:::-> | $ (echo "..."; tail -4) -:::-- background.stop(name: "local1") -``` - -Just like the Heroku platform, `heroku local` examines your `Procfile` to determine what command to run. - -Open [http://localhost:5000](http://localhost:5000) with your web browser. You should see your app running locally. - -To stop the app from running locally, go back to your terminal window and press `CTRL+C` to exit. - -

Push local changes

- -In this step you'll learn how to make local changes to your app and deploy them to Heroku. As an example, you'll add a dependency and some code that uses it. - -Modify `pom.xml` to include a dependency for `jscience` by adding the following code inside the `` element: - -```xml -:::>> file.append pom.xml#28 - - org.jscience - jscience - 4.3.1 - -``` - -Now add the following `import` statements to `src/main/java/com/example/Main.java` to import the library: - -```java -:::>> file.append src/main/java/com/example/Main.java#19 -import static javax.measure.unit.SI.KILOGRAM; -import javax.measure.quantity.Mass; -import org.jscience.physics.model.RelativisticModel; -import org.jscience.physics.amount.Amount; -``` - -Add the following `hello ` method to `Main.java`: - -```java -:::>> file.append src/main/java/com/example/Main.java#59 -@RequestMapping("/hello") -String hello(Map model) { - RelativisticModel.select(); - Amount m = Amount.valueOf("12 GeV").to(KILOGRAM); - model.put("science", "E=mc^2: 12 GeV = " + m.toString()); - return "hello"; -} -``` - -Finally, create a `src/main/resources/templates/hello.html` file with these contents: - -```xml -:::>> file.write src/main/resources/templates/hello.html - - - -
-

-

- - -``` - -[Here's the final source code](https://github.com/heroku/java-getting-started/blob/localchanges/src/main/java/com/example/Main.java) for `Main.java` - yours should look similar. [Here's a diff](https://github.com/heroku/java-getting-started/compare/localchanges) of all the local changes you should have made. - -Now test your changes locally: - -```term -:::>- $ mvn clean install -:::-> | $ (echo "..."; tail -7) -:::>- background.start("heroku local web", name: "local2", wait: "Tomcat started", timeout: 30) -:::-> | $ (echo "..."; tail -4) -:::-- background.stop(name: "local2") -``` - -Visiting your application's `/hello` path at [http://localhost:5000/hello](http://localhost:5000/hello), you should see some great scientific conversions displayed: - - E=mc^2: 12 GeV = (2.139194076302506E-26 ± 1.4E-42) kg - -Now you can deploy. Almost every Heroku deployment follows this same pattern. First, use the `git add` command to stage your modified files for commit: - -```term -:::>- $ git add . -``` - -Next, commit the changes to the repository: - -```term -:::>- $ git commit -m "Demo" -``` - -Now deploy, just as you did previously: - -```term -:::>- $ git push heroku master -``` - -Finally, check that your updated code is successfully deployed: - -```term -:::>- $ heroku open hello -``` - -

Define config vars

- -Heroku lets you externalize your app's configuration by storing data such as encryption keys or external resource addresses in [config vars](config-vars). - -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: - -``` -:::-- $ sed -e '56,68d' src/main/java/com/example/Main.java -``` - -```java -:::>> file.append("src/main/java/com/example/Main.java#56") -@RequestMapping("/hello") -String hello(Map model) { - RelativisticModel.select(); - String energy = System.getenv().get("ENERGY"); - if (energy == null) { - energy = "12 GeV"; - } - Amount m = Amount.valueOf(energy).to(KILOGRAM); - model.put("science", "E=mc^2: " + energy + " = " + m.toString()); - return "hello"; -} -``` - -Now compile the app again so that this change is integrated by running `mvn clean install`. - -`heroku local` automatically sets up your local environment based on the contents of the `.env` file in your app's root directory. Your sample app already includes a `.env` file with the following contents: - -``` -ENERGY=20 GeV -``` - ->warning ->Your own apps should _not_ commit the `.env` file to version control, because it often includes secure credentials. Include `.env` in your repo's `.gitignore` file. - -If you run the app with `heroku local` and visit it at [http://localhost:5000/hello](http://localhost:5000/hello), you'll see the conversion value for 20 GeV. - -To set the config var on Heroku, execute the following: - -```term -:::>> $ heroku config:set ENERGY="20 GeV" -``` - -View the config vars that are set using `heroku config`: - -```term -:::>> $ heroku config -``` - -Deploy your updated application to Heroku to see this in action. - -

Start a one-off dyno

- -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: - -```term -:::>- $ heroku run java -version -:::-> | $ tail -4 -``` - -If you receive an error, `Error connecting to process`, then you might need to [configure your firewall](one-off-dynos#timeout-awaiting-process). - -Don’t forget to type `exit` to exit the shell and terminate the dyno. - -

Provision add-ons

- -Add-ons are cloud services that provide additional services for your application, such as databases, logging, and monitoring. - -By default, Heroku stores your app's 1500 most recent log lines. However, the full log stream is available as a service, and several logging add-ons are available that provide features such as log persistence, search, and alerting. - -In this step you'll provision one of these logging add-ons, Papertrail. - -Provision the [Papertrail](papertrail) add-on like so: - -```term -:::>> $ heroku addons:create papertrail -``` - ->callout ->To help prevent abuse, provisioning an add-on requires [account verification](account-verification). If your account has not been verified, you will be directed to visit the [verification site](https://heroku.com/verify). - -The add-on is now deployed and configured for your application. You can list your app's active add-ons like so: - -```term -:::>- $ heroku addons -``` - -To see this particular add-on in action, visit your application's Heroku URL a few times. Each visit generates more log messages, which should now be routed to the Papertrail add-on. Visit the Papertrail console to see the log messages: - -```term -:::>- $ heroku addons:open papertrail -``` - -Your browser will open up a Papertrail web console that shows the latest log events. The interface lets you search and set up alerts: - -![Image](https://s3.amazonaws.com/heroku-devcenter-files/article-images/2205-imported-1443570572-2205-imported-1443555048-360-original.jpg 'add-on sample output') - -

Use a database

- -Heroku provides managed data services for Postgres and Redis, and the [add-on marketplace](https://elements.heroku.com/addons/categories/data-stores) provides a variety of additional data services, including MongoDB and MySQL. - -In this step you'll learn about the free Heroku Postgres add-on that is provisioned automatically with all Java app deploys. - -Heroku Postgres is itself an add-on, so you can use the `heroku addons` command for an overview of the database provisioned for your app: - -```term -:::>> $ heroku addons -``` - -Listing your app's config vars will display the URL that your app is using to connect to the database (`DATABASE_URL`): - -```term -:::>> $ heroku config -``` - -The `heroku pg` command provides more in-depth information on your app's Heroku Postgres databases: - -```term -:::>> $ heroku pg -``` - -This indicates that the app has a `Hobby-dev` database (the free plan), running Postgres 9.3.3, currently with zero rows of data. - -The example app you deployed already has database functionality, which you can reach by visiting your app's `/db` path. For example, if your app's root URL is `https://wonderful-app-287.herokuapp.com/` then visit `https://wonderful-app-287.herokuapp.com/db`. - -The code to access the database is straightforward. Here's the method to insert values into a table called `tick`: - -```java -:::-> $ sed -n '45,50p;78,109p' src/main/java/com/example/Main.java -``` - -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. - -The HikariCP database connection pool is initialized with the configuration value `spring.datasource.url`, which is defined in `src/main/resources/application.properties` like this: - -``` -:::-> $ sed -n '1p' src/main/resources/application.properties -``` - -This sets `spring.datasource.url` to the value in the `JDBC_DATABASE_URL` environment variable, [set by the database add-on](articles/connecting-to-relational-databases-on-heroku-with-java), and establishes a pool of connections to the database. - -Deploy your changes to Heroku. Now, when you access your app's `/db` route, you will see something like this: - -``` -Database Output -* Read from DB: 2014-08-08 14:48:25.155241 -* Read from DB: 2014-08-08 14:51:32.287816 -* Read from DB: 2014-08-08 14:51:52.667683 -``` - -Assuming that you have [Postgres installed locally](heroku-postgresql#local-setup), use the `heroku pg:psql` command to connect to the remote database and see all the rows: - -```term -$ heroku pg:psql -psql (10.1, server 9.6.10) -SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) -Type "help" for help. - -DATABASE=> SELECT * FROM ticks; - tick ----------------------------- -2018-03-01 20:53:27.148139 -2018-03-01 20:53:29.288995 -2018-03-01 20:53:29.957118 -2018-03-01 21:07:28.880162 -(4 rows) -=> \q -``` - -Read more about [Heroku PostgreSQL](heroku-postgresql). - -A similar technique can be used to install [MongoDB or Redis add-ons](https://elements.heroku.com/addons/categories/data-stores). - - -## Next steps - -Congratulations! You now know how to deploy an app, change its configuration, scale it, view logs, and attach add-ons. - -Here's some recommended reading to continue your Heroku journey: - -* [How Heroku Works](how-heroku-works) provides a technical overview of the concepts you’ll encounter while writing, configuring, deploying, and running apps. -* The [Java category](/categories/java-support) provides more in-depth information on developing and deploying Java apps. -* The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments. diff --git a/setenv-sample.cmd b/setenv-sample.cmd new file mode 100644 index 00000000..6e8d1b95 --- /dev/null +++ b/setenv-sample.cmd @@ -0,0 +1,10 @@ +@echo on +set PORT=5000 +set MAIL_SMTP_HOST=mailhost +set MAIL_SMTP_PORT=465 +set MAIL_SMTP_USERNAME='mailuser' +set MAIL_SMTP_PASSWORD='mailuserpassword' +set MAIL_FROM='noreply@example.org' +set MAIL_URL_APP_HOST='localhost:5000' +set JPA_DLL_AUTO='update' +#set JPA_DLL_AUTO='create-drop'