Scala+DBMS+Web スカラ座の夜

2011年12月17日

HerokuにEmbedded TomcatヘJava Web Applicationを作る

Filed under: Java — admin @ 12:39 AM

HEROKUが正式にScala言語をサポートしたということで、その前段としてJavaアプリケーションを作ってみました。

詳細は、HEROKUの開発者向けページの以下のURLに説明があります。

http://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat

まずは、前提となる環境を作ります。

1. JVMをインストールします。
  現在のJava環境は、Java Platform, Standard Edition のJava SE 7 Update 1をインストールしています。

以下のURLからインストール用のJDKをダウンロードします。
http://www.oracle.com/technetwork/jp/java/javase/downloads/index.html

2. Maven環境は、次のようになっています。

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

Maven環境は、

C:> mvn -version
Apache Maven 3.0.3 (r1075438; 2011-03-01 02:31:09+0900)
Maven home: C:\apache-maven-3.0.3\bin\..
Java version: 1.7.0_01, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_01\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

以下のURLからダウンロードできます。
http://maven.apache.org/download.html
http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0.3-bin.zip

Maven 2.2.1でもOKです。新しいもの好きなので3.0.3を使っています。

3. Git
使っているバージョンは以下のものですが、この文章を書いているときの最新はv1.7.7.5です。

Welcome to Git (version 1.7.6-preview20110708)

Gitは以下のURLからダウンロードできます。
http://git-scm.com/

これらをPCにインストールします。

4. pom.xml
Mavenを使うには、pom.xmlを定義します。
これは、HEROKUには、


4.0.0
com.heroku.sample
embeddedTomcatSample
1.0-SNAPSHOT
embeddedTomcatSample Maven Webapp
http://maven.apache.org


org.apache.tomcat.embed
tomcat-embed-core
7.0.22


org.apache.tomcat.embed
tomcat-embed-logging-juli
7.0.22


org.apache.tomcat.embed
tomcat-embed-jasper
7.0.22


org.apache.tomcat
tomcat-jasper
7.0.22


org.apache.tomcat
tomcat-jasper-el
7.0.22


org.apache.tomcat
tomcat-jsp-api
7.0.22



embeddedTomcatSample org.codehaus.mojo
appassembler-maven-plugin
1.1.1

target launch.Main
webapp


package
assemble



このファイルを、Eclipseからも使いたいので、
C:\User\XXX\workspace\Heroku\ディレクトリに置きます。

5. MVN
mvn をpom.xml ファイルがある場所で実行します。


$ mvn package

mvn を実行すると以下のような感じファイルがダウンロードされ、環境が構築されます。

[INFO] ------------------------------------------------------------------------
[INFO] Building embeddedTomcatSample Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-surefi
re-plugin/2.7.2/maven-surefire-plugin-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-surefir
e-plugin/2.7.2/maven-surefire-plugin-2.7.2.pom (10 KB at 8.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire/2.
7.2/surefire-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire/2.7
.2/surefire-2.7.2.pom (11 KB at 23.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-surefi
re-plugin/2.7.2/maven-surefire-plugin-2.7.2.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-surefir
e-plugin/2.7.2/maven-surefire-plugin-2.7.2.jar (29 KB at 33.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler-maven-
plugin/1.1.1/appassembler-maven-plugin-1.1.1.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler-maven-p
lugin/1.1.1/appassembler-maven-plugin-1.1.1.pom (8 KB at 18.6 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appass
embler/1.1.1/appassembler-1.1.1.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appasse
mbler/1.1.1/appassembler-1.1.1.pom (6 KB at 9.8 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/27/mojo
-parent-27.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/mojo-parent/27/mojo-
parent-27.pom (27 KB at 56.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/codehaus-parent/3/codeha
us-parent-3.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/codehaus-parent/3/codehau
s-parent-3.pom (5 KB at 8.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler-maven-
plugin/1.1.1/appassembler-maven-plugin-1.1.1.jar
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler-maven-p
lugin/1.1.1/appassembler-maven-plugin-1.1.1.jar (762 KB at 408.6 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
core/7.0.22/tomcat-embed-core-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-c
ore/7.0.22/tomcat-embed-core-7.0.22.pom (2 KB at 3.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
logging-juli/7.0.22/tomcat-embed-logging-juli-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-l
ogging-juli/7.0.22/tomcat-embed-logging-juli-7.0.22.pom (2 KB at 2.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
jasper/7.0.22/tomcat-embed-jasper-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-j
asper/7.0.22/tomcat-embed-jasper-7.0.22.pom (2 KB at 2.2 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.2
2/tomcat-jasper-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.22
/tomcat-jasper-7.0.22.pom (3 KB at 4.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/
7.0.22/tomcat-servlet-api-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/7
.0.22/tomcat-servlet-api-7.0.22.pom (2 KB at 2.0 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-juli/7.0.22/
tomcat-juli-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-juli/7.0.22/t
omcat-juli-7.0.22.pom (2 KB at 2.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jsp-api/7.0.
22/tomcat-jsp-api-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jsp-api/7.0.2
2/tomcat-jsp-api-7.0.22.pom (2 KB at 3.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-el-api/7.0.2
2/tomcat-el-api-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-el-api/7.0.22
/tomcat-el-api-7.0.22.pom (2 KB at 2.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/3.7
/ecj-3.7.pom
Downloaded: http://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/3.7/
ecj-3.7.pom (2 KB at 2.6 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper-el/7.
0.22/tomcat-jasper-el-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper-el/7.0
.22/tomcat-jasper-el-7.0.22.pom (2 KB at 2.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-api/7.0.22/t
omcat-api-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-api/7.0.22/to
mcat-api-7.0.22.pom (2 KB at 2.7 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-util/7.0.22/
tomcat-util-7.0.22.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-util/7.0.22/t
omcat-util-7.0.22.pom (2 KB at 2.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
core/7.0.22/tomcat-embed-core-7.0.22.jar
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
jasper/7.0.22/tomcat-embed-jasper-7.0.22.jar
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/
7.0.22/tomcat-servlet-api-7.0.22.jar
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.2
2/tomcat-jasper-7.0.22.jar
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-
logging-juli/7.0.22/tomcat-embed-logging-juli-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-c
ore/7.0.22/tomcat-embed-core-7.0.22.jar (2379 KB at 1313.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-juli/7.0.22/
tomcat-juli-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/7
.0.22/tomcat-servlet-api-7.0.22.jar (173 KB at 74.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-el-api/7.0.2
2/tomcat-el-api-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-l
ogging-juli/7.0.22/tomcat-embed-logging-juli-7.0.22.jar (38 KB at 14.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/3.7
/ecj-3.7.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-juli/7.0.22/t
omcat-juli-7.0.22.jar (38 KB at 36.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-api/7.0.22/t
omcat-api-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper/7.0.22
/tomcat-jasper-7.0.22.jar (577 KB at 150.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-util/7.0.22/
tomcat-util-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-el-api/7.0.22
/tomcat-el-api-7.0.22.jar (43 KB at 23.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper-el/7.
0.22/tomcat-jasper-el-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-j
asper/7.0.22/tomcat-embed-jasper-7.0.22.jar (768 KB at 178.0 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jsp-api/7.0.
22/tomcat-jsp-api-7.0.22.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-api/7.0.22/to
mcat-api-7.0.22.jar (7 KB at 3.7 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-util/7.0.22/t
omcat-util-7.0.22.jar (23 KB at 12.9 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jsp-api/7.0.2
2/tomcat-jsp-api-7.0.22.jar (87 KB at 49.8 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/tomcat/tomcat-jasper-el/7.0
.22/tomcat-jasper-el-7.0.22.jar (120 KB at 54.6 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/3.7/
ecj-3.7.jar (1671 KB at 422.9 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ embedded
TomcatSample ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered resources, i
.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\ewave\workspace\HEROKU\src\m
ain\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ embeddedTomca
tSample ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @
embeddedTomcatSample ---
[WARNING] Using platform encoding (MS932 actually) to copy filtered resources, i
.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\ewave\workspace\HEROKU\src\t
est\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ embed
dedTomcatSample ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ embeddedTomcatSampl
e ---
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-bo
oter/2.7.2/surefire-booter-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-boo
ter/2.7.2/surefire-booter-2.7.2.pom (2 KB at 3.8 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-ap
i/2.7.2/surefire-api-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-api
/2.7.2/surefire-api-2.7.2.pom (2 KB at 4.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/maven-suref
ire-common/2.7.2/maven-surefire-common-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/maven-surefi
re-common/2.7.2/maven-surefire-common-2.7.2.pom (4 KB at 6.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-common-
artifact-filters/1.3/maven-common-artifact-filters-1.3.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-common-a
rtifact-filters/1.3/maven-common-artifact-filters-1.3.pom (4 KB at 5.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-bo
oter/2.7.2/surefire-booter-2.7.2.jar
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-ap
i/2.7.2/surefire-api-2.7.2.jar
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/maven-suref
ire-common/2.7.2/maven-surefire-common-2.7.2.jar
Downloading: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-common-
artifact-filters/1.3/maven-common-artifact-filters-1.3.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-boo
ter/2.7.2/surefire-booter-2.7.2.jar (32 KB at 26.9 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/maven-surefi
re-common/2.7.2/maven-surefire-common-2.7.2.jar (60 KB at 38.5 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-common-a
rtifact-filters/1.3/maven-common-artifact-filters-1.3.jar (31 KB at 16.8 KB/sec)

Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-api
/2.7.2/surefire-api-2.7.2.jar (119 KB at 57.5 KB/sec)
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Users\ewave\workspace\HEROKU\target\surefir
e-reports
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-ju
nit3/2.7.2/surefire-junit3-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-jun
it3/2.7.2/surefire-junit3-2.7.2.pom (2 KB at 3.8 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-pr
oviders/2.7.2/surefire-providers-2.7.2.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-pro
viders/2.7.2/surefire-providers-2.7.2.pom (2 KB at 3.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-ju
nit3/2.7.2/surefire-junit3-2.7.2.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-jun
it3/2.7.2/surefire-junit3-2.7.2.jar (26 KB at 54.2 KB/sec)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ embeddedTomcatSample ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\Users\ewave\workspace\HEROKU\target\embeddedTomcatSample
.jar
[INFO]
[INFO] --- appassembler-maven-plugin:1.1.1:assemble (default) @ embeddedTomcatSa
mple ---
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appass
embler-model/1.1.1/appassembler-model-1.1.1.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appasse
mbler-model/1.1.1/appassembler-model-1.1.1.pom (4 KB at 7.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/net/java/dev/stax-utils/stax-utils/20
060502/stax-utils-20060502.pom
Downloaded: http://repo1.maven.org/maven2/net/java/dev/stax-utils/stax-utils/200
60502/stax-utils-20060502.pom (565 B at 1.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/stax/stax/1.1.1-dev/stax-1.1.1-dev.po
m
Downloaded: http://repo1.maven.org/maven2/stax/stax/1.1.1-dev/stax-1.1.1-dev.pom
 (3 KB at 7.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/junit/junit/3.8.2/junit-3.8.2.pom
Downloaded: http://repo1.maven.org/maven2/junit/junit/3.8.2/junit-3.8.2.pom (747
 B at 1.5 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appass
embler-model/1.1.1/appassembler-model-1.1.1.jar
Downloading: http://repo1.maven.org/maven2/net/java/dev/stax-utils/stax-utils/20
060502/stax-utils-20060502.jar
Downloading: http://repo1.maven.org/maven2/stax/stax/1.1.1-dev/stax-1.1.1-dev.ja
r
Downloaded: http://repo1.maven.org/maven2/org/codehaus/mojo/appassembler/appasse
mbler-model/1.1.1/appassembler-model-1.1.1.jar (24 KB at 21.4 KB/sec)
Downloaded: http://repo1.maven.org/maven2/stax/stax/1.1.1-dev/stax-1.1.1-dev.jar
 (166 KB at 69.4 KB/sec)
Downloaded: http://repo1.maven.org/maven2/net/java/dev/stax-utils/stax-utils/200
60502/stax-utils-20060502.jar (126 KB at 48.0 KB/sec)
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\embed\tomcat-e
mbed-core\7.0.22\tomcat-embed-core-7.0.22.jar to C:\Users\ewave\workspace\HEROKU
\target\repo\org\apache\tomcat\embed\tomcat-embed-core\7.0.22\tomcat-embed-core-
7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\embed\tomcat-e
mbed-logging-juli\7.0.22\tomcat-embed-logging-juli-7.0.22.jar to C:\Users\ewave\
workspace\HEROKU\target\repo\org\apache\tomcat\embed\tomcat-embed-logging-juli\7
.0.22\tomcat-embed-logging-juli-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\embed\tomcat-e
mbed-jasper\7.0.22\tomcat-embed-jasper-7.0.22.jar to C:\Users\ewave\workspace\HE
ROKU\target\repo\org\apache\tomcat\embed\tomcat-embed-jasper\7.0.22\tomcat-embed
-jasper-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-jasper\
7.0.22\tomcat-jasper-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo\o
rg\apache\tomcat\tomcat-jasper\7.0.22\tomcat-jasper-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-servlet
-api\7.0.22\tomcat-servlet-api-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\tar
get\repo\org\apache\tomcat\tomcat-servlet-api\7.0.22\tomcat-servlet-api-7.0.22.j
ar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-juli\7.
0.22\tomcat-juli-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo\org\a
pache\tomcat\tomcat-juli\7.0.22\tomcat-juli-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-el-api\
7.0.22\tomcat-el-api-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo\o
rg\apache\tomcat\tomcat-el-api\7.0.22\tomcat-el-api-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\eclipse\jdt\core\compiler\ec
j\3.7\ecj-3.7.jar to C:\Users\ewave\workspace\HEROKU\target\repo\org\eclipse\jdt
\core\compiler\ecj\3.7\ecj-3.7.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-api\7.0
.22\tomcat-api-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo\org\apa
che\tomcat\tomcat-api\7.0.22\tomcat-api-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-util\7.
0.22\tomcat-util-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo\org\a
pache\tomcat\tomcat-util\7.0.22\tomcat-util-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-jasper-
el\7.0.22\tomcat-jasper-el-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\
repo\org\apache\tomcat\tomcat-jasper-el\7.0.22\tomcat-jasper-el-7.0.22.jar
[INFO] Installing C:\Users\ewave\.m2\repository\org\apache\tomcat\tomcat-jsp-api
\7.0.22\tomcat-jsp-api-7.0.22.jar to C:\Users\ewave\workspace\HEROKU\target\repo
\org\apache\tomcat\tomcat-jsp-api\7.0.22\tomcat-jsp-api-7.0.22.jar
[INFO] Installing C:\Users\ewave\workspace\HEROKU\target\embeddedTomcatSample.ja
r to C:\Users\ewave\workspace\HEROKU\target\repo\com\heroku\sample\embeddedTomca
tSample\1.0-SNAPSHOT\embeddedTomcatSample-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 38.329s
[INFO] Finished at: Sat Dec 17 15:54:28 JST 2011
[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS と表示されれば成功。

6. Launcher Class
TOMCATを起動させるためのJavaコードは以下の通りです。
このファイルを、C:\User\XXX\workspace\Heroku\src\main\java\launchディレクトリに置きます。


package launch;

import java.io.File;
import org.apache.catalina.startup.Tomcat;

public class Main {

public static void main(String[] args) throws Exception {

String webappDirLocation = “src/main/webapp/”;
Tomcat tomcat = new Tomcat();

//The port that we should run on can be set into an environment variable
//Look for that variable and default to 8080 if it isn’t there.
String webPort = System.getenv(“PORT”);
if(webPort == null || webPort.isEmpty()) {
webPort = “8080”;
}

tomcat.setPort(Integer.valueOf(webPort));

tomcat.addWebapp(“/”, new File(webappDirLocation).getAbsolutePath());
System.out.println(“configuring app with basedir: ” + new File(“./” + webappDirLocation).getAbsolutePath());

tomcat.start();
tomcat.getServer().await();
}
}

7.Servlet
Servletのコードは以下のとおり。
C:\User\XXX\workspace\Heroku\src\main\java\servlet\ディレクトリに置きます。


package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
name = “MyServlet”,
urlPatterns = {“/hello”}
)
public class HelloServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletOutputStream out = resp.getOutputStream();
out.write(“hello heroku”.getBytes());
out.flush();
out.close();
}

}

8. JSP
JSPファイルを作ります。
C:\Users\XXX\workspace\Heroku\target\bin\src\main\webapp\ディレクトリにindex.jspファイルを置きます。


<html>
<body>
<h2>Hello Heroku!</h2>
</body>
</html>

9. MVNコマンド
JAVAコードをコンパイルなどするために再びMVNを実行します。


$ mvn package

10.TOMCATの起動
TOMCATを起動するためにバッチファイルを実行します。


$ target/bin/webapp.bat

ブラウザでServletをアクセスするには以下のURLを。

http://localhost:8080/hello

JSPをアクセスするには以下のURLです。

http://localhost:8080

Hello Heroku! とブラウザ画面に表示されます。

Servletでは、

hello heroku

とブラウザ画面に表示されればOKです。

11.Procfile

Procfileファイルを作成します。
このファイルの中身は、

web: sh target/bin/webapp

このファイルによってHEROKUでアプリがHEROKUにデプロイされます。

次は、このTOMCATをHEROKUへデプロイする手順です。

Comments

comments

Powered by Facebook Comments

コメントはまだありません »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

コメントを投稿するにはログインしてください。

Powered by WordPress