1、start
In this step you will install the Heroku Toolbelt. This provides you access to the Heroku Command Line utility, as well as git and Foreman, tools you’ll use in later steps.
Once installed, you can use the heroku
command from your command shell.
Git Bash
application to open a command shell on Windows. A shortcut for this application was added to your desktop as part of the Toolbelt installation.
Log in using the email address and password you used when creating your Heroku account:
$ heroku login Enter your Heroku credentials. Email: java@example.com Password: Could not find an existing public key. Would you like to generate one? [Yn] Generating new SSH public key. Uploading ssh public key /Users/java/.ssh/id_rsa.pub
Press enter at the prompt to upload your existing ssh
key or create a new one, used for pushing code later on.
To check that your key was added, type heroku keys
. If your key isn’t there, you can add it manually by typing heroku keys:add
. For more information about SSH keys, seeManaging Your SSH Keys.
In this step, you will prepare a simple application that can be deployed.
Execute the following commands to clone the sample application:
$ git clone https://github.com/heroku/java-getting-started.git $ cd java-getting-started
You now have a functioning git repository that contains a simple application as well as apom.xml
file, which is used by Java’s dependency manager, Maven.
In this step you will deploy the app to Heroku.
Create an app on Heroku, which prepares Heroku to receive your source code:
$ heroku create Creating warm-eyrie-9006... done, stack is cedar http://warm-eyrie-9006.herokuapp.com/ | git@heroku.com:warm-eyrie-9006.git Git remote heroku added
This also creates a remote repository (called heroku
) which it configures in your local git repo. Heroku generates a random name (in this case warm-eyrie-9006
) for your app - you can pass a parameter to specify your own, or rename it later with heroku apps:rename
.
Now deploy your code:
$ git push heroku master Initializing repository, done. Counting objects: 68, done. Delta compression using up to 4 threads. Compressing objects: 100% (19/19), done. Writing objects: 100% (68/68), 7.07 KiB | 0 bytes/s, done. Total 68 (delta 22), reused 65 (delta 22) -----> Java app detected -----> Installing OpenJDK 1.7... done -----> Installing Maven 3.0.3... done -----> executing /app/tmp/cache/.maven/bin/mvn -B -Duser.home=/tmp/build_4244c199-7f9b-4f62-bf60-bbd0aff3f978 -Dmaven.repo.local=/app/tmp/cache/.m2/repository -DskipTests=true clean install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building helloworld 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.4/maven-dependency-plugin-2.4.pom ... -----> Discovering process types Procfile declares types -> web -----> Compressing... done, 62.7MB -----> Launching... done, v7 http://warm-eyrie-9006.herokuapp.com/ deployed to Heroku To git@heroku.com:warm-eyrie-9006.git * [new branch] master -> master
The application is now deployed. Ensure that at least one instance of the app is running:
$ 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 as follows:
$ heroku open
Heroku treats logs as streams of time-ordered events aggregated from the output streams of all your app and Heroku components, providing a single channel for all of the events.
View information about your running app using one of the logging commands, heroku logs
:
$ heroku logs --tail 2014-08-08T13:55:07.254053+00:00 heroku[web.1]: State changed from starting to up 2014-08-08T13:55:05.214125+00:00 heroku[web.1]: Starting process with command `java -Xmx384m -Xss512k -XX:+UseCompressedOops -cp target/classes:target/dependency/* Main` 2014-08-08T13:56:08.662643+00:00 heroku[router]: at=info method=GET path="/" host=warm-eyrie-9006.herokuapp.com request_id=f99b4889-1b16-4862-876d-4f752ad3d843 fwd="94.174.204.242" dyno=web.1 connect=1ms service=3ms status=200 bytes=579
Visit your application in the browser again, and you’ll see another log message generated. Press Control+C
to stop streaming the logs.