Pre-preparation
- Download Heroku Toolbelt Tools
- Heroku login command, set Heroku's mailbox and password
- Official documentation for deploying Java applications using Jetty-runner
- Getting Started with Spring MVC Hibernate on Heroku (https://devcenter.heroku.com/articles/ Getting-started-with-spring-mvc-hibernate)
- Create a Java Web application Using Embedded Tomcat (https://devcenter.heroku.com/articles/ CREATE-A-JAVA-WEB-APPLICATION-USING-EMBEDDED-TOMCAT)
Create a MVN project
//创建webapp类型的mvn项目-DarchetypeArtifactId=maven-archetype-webapp
If you created with eclipse, you can view: Create a MVN project in eclipse
Add the Jetty-runner server to the Pom.xml file
<build>...<plugins>...<plugin> <groupId>Org.apache.maven.plugins</groupId> <artifactid>Maven-dependency-plugin</artifactid> <version>2.3</version> <executions> <execution> <phase>Package</phase> <goals><goal>Copy</goal></goals> <configuration> <artifactitems> <artifactitem> <groupId>Org.mortbay.jetty</groupId> <artifactid>Jetty-runner</artifactid> <version>7.5.4.v20111024</version> <destfilename>Jetty-runner.jar</destfilename> </artifactitem> </artifactitems> </configuration> </Execution> </executions> </plugin> </plugins></Build>
Execute the MVN package command to download the Jar pack and package it to target, and if not packaged, an error occurs when running the server locally
Create a Procfile file
For Unix-like systems, add the following line:
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
If you are a Windows system:
web: java -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
$ JAVA_OPTS
And: cannot be used under Windows, so to replace, *.war can use Applicationname.war
Create a System.properties file
Add the following line:
java.runtime.version=1.7
Heroku default is 1.6
Add Git version control
commit -m"ready to deploy"
Create a. gitignore file
In the file, add:
Target
Deploying Apps to Heroku
create [name] //创建heroku应用,name为可选git push heroku master heroku ps:scale web=1//设置dynos为一个,heroku只提供一个免费的dynoopen //打开页面foreman start web -f Procfile.windows //在本地运行应用,http://localhost:5000,若为linux系统则可以省略-f 。。。
Heroku Deploying Java Web Projects