在Heroku平台上部署maven webapp(java web)项目

目前,想要在Heroku上面部署java web项目,该项目就必须用maven管理

一:新建maven webapp项目

编辑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.lala</groupId>
    <artifactId>tangshiyi</artifactId>
    <packaging>war</packaging>
    <version>1.0.0</version>

    <name>tangshiyi Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</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>jeecms</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>tangshiyi</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


二:编写运行war包的命令

在项目的根目录下新建

Procfile 文件(注意文件名要一模一样)


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


注意这里的war包的名字需要和上面pom.xml里面配置的要一样


三:在github上面创建tangshiyi项目,并刚才创建的项目push上去

四:在heroku上面新建一个应用并关联github上面刚刚新建的项目,部署即可

五:访问

https://${xxxx}.herokuapp.com/

${xxxx}为第四步创建应用的名字


---------------------------------------------------

maven技术交流群:379165311,欢迎大家加入


你可能感兴趣的:(heroku)