于Heroku平台部署maven webapp(java web)工程

2022-07-06 18:25:29 浏览数 (1)

大家好,又见面了,我是全栈君

眼下,需要Heroku上述部署java web工程,该项目必须使用maven管理

一:新maven webapp工程

编者pom.xml档,增加下面的配置为例,

代码语言:javascript复制
<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,欢迎来到增长

版权声明:本文博主原创文章,博客,未经同意不得转载。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116853.html原文链接:https://javaforall.cn

0 人点赞