使用snap ci+GitHub将一个Java Web项目部署到Heroku

网站地址:

Snap ci:https://snap-ci.com

Heroku:https://devcenter.heroku.com/

GitHub:https://github.com


新建一个java web 的Maven项目

注意事项:

1.在pom.xml中添加如下配置:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.zjh.wechat</groupId>
  <artifactId>heroku-demo</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>heroku-demo Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
  </dependencies>
  <build>
    <finalName>heroku-demo</finalName>
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.eclipse.jetty</groupId>
                                    <artifactId>jetty-runner</artifactId>
                                    <version>9.2.11.v20150529</version>
                                    <destFileName>jetty-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warName>你的war包名(名字自己起)</warName><!--war包名-->
                </configuration>
            </plugin>
        </plugins>
  </build>
</project>
2.在项目根目录下新建两个文件:Profile和system.properties

Profile的配置如下,其中war包名必须和pom.xml中配置的war包名一致,Profile的配置十分的重要,它决定了你的应用的入口。

web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/war包名

system.properties

java.runtime.version=1.8

3.将项目上传到github,进入Snap CI,使用github账户登录,在Repository选择你要发布的项目,点击Add添加


4.点击Add Stage进行部署



出现如下画面,就表示发布成功


接下来,就可以使用:你的应用名称.heroku.com访问你的应用了。应用名可以点击上图的deploy logs 部分,可以在日志的底部看到你发布的应用的名称


使用Snap CI 发布项目的一个好处是:它会帮你自动地持续集成你的项目,Snap CI发现你的项目有变化时,它会自动的帮你部署,而你只需要注重项目的开发即可。


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值