1
- This quickstart will get you going with Java and the [ Jetty] ( http://eclipse.org/jetty/ ) embedded web server, deployed to Heroku.
2
-
3
- {.note}
4
- Sample code for the [ Java demo application] ( https://github.com/heroku/devcenter-java ) is available on GitHub. Edits and enhancements are welcome.
1
+ This quickstart will get you going with Java and the [ Jetty] ( http://eclipse.org/jetty/ ) embedded web server.
5
2
6
3
## Prerequisites
7
4
8
5
* Basic Java knowledge, including an installed version of the JVM and [ Maven 3] ( http://maven.apache.org/download.html ) .
9
6
* Your application must run on the [ OpenJDK] ( http://openjdk.java.net/ ) version 6, or 7 (8 is also available in beta).
10
- * A Heroku user account. [ Signup is free and instant.] ( https://api.heroku.com/signup/devcenter )
11
7
12
8
## Local workstation setup
13
9
@@ -19,16 +15,16 @@ Once installed, you can use the `heroku` command from your command shell. Log i
19
15
$ heroku login
20
16
Enter your Heroku credentials.
21
17
22
- Password:
18
+ Password:
23
19
Could not find an existing public key.
24
- Would you like to generate one? [Yn]
20
+ Would you like to generate one? [Yn]
25
21
Generating new SSH public key.
26
22
Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
27
23
28
24
Press enter at the prompt to upload your existing ` ssh ` key or create a new one, used for pushing code later on.
29
25
30
26
## Write your app
31
-
27
+
32
28
You can run any Java application on Heroku that uses Maven as build tool. As an example, we will write a web app using Jetty. Here is a basic servlet class that also contains a main method to start up the application:
33
29
34
30
### src/main/java/HelloWorld.java
@@ -55,7 +51,7 @@ You can run any Java application on Heroku that uses Maven as build tool. As an
55
51
server.setHandler(context);
56
52
context.addServlet(new ServletHolder(new HelloWorld()),"/*");
57
53
server.start();
58
- server.join();
54
+ server.join();
59
55
}
60
56
}
61
57
@@ -67,8 +63,8 @@ Cedar recognizes Java apps by the existence of a `pom.xml` file. Here's an examp
67
63
68
64
:::xml
69
65
<?xml version="1.0" encoding="UTF-8"?>
70
- <project xmlns="http://maven.apache.org/POM/4.0.0"
71
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
67
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
72
68
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
73
69
<modelVersion>4.0.0</modelVersion>
74
70
<groupId>com.example</groupId>
@@ -141,7 +137,7 @@ You should now see something similar to:
141
137
2012-01-31 15:51:21.931:INFO:oejsh.ContextHandler:started o.e.j.s.ServletContextHandler{/,null}
142
138
2012-01-31 15:51:21.971:INFO:oejs.AbstractConnector:Started [email protected] :5000
143
139
144
- Open the app in your browser:
140
+ Open the app in your browser:
145
141
[ http://localhost:5000 ] ( http://localhost:5000 )
146
142
147
143
@@ -202,7 +198,7 @@ Deploy your code:
202
198
-----> Installing settings.xml... done
203
199
-----> executing /app/tmp/repo.git/.cache/.maven/bin/mvn -B -Duser.home=/tmp/build_3k0p14ghrmdzs -Dmaven.repo.local=/app/tmp/repo.git/.cache/.m2/repository -s /app/tmp/repo.git/.cache/.m2/settings.xml -DskipTests=true clean install
204
200
[INFO] Scanning for projects...
205
- [INFO]
201
+ [INFO]
206
202
[INFO] ------------------------------------------------------------------------
207
203
[INFO] Building helloworld 1.0-SNAPSHOT
208
204
[INFO] ------------------------------------------------------------------------
@@ -224,9 +220,9 @@ Now, let's check the state of the app's processes:
224
220
225
221
:::term
226
222
$ heroku ps
227
- Process State Command
228
- ------- ---------- ------------------------------------
229
- web.1 up for 10s java -cp target/classes:target/dep..
223
+ Process State Command
224
+ ------- ---------- ------------------------------------
225
+ web.1 up for 10s java -cp target/classes:target/dep..
230
226
231
227
The web process is up. Review the logs for more information:
232
228
0 commit comments