使用 Tomcat 和 Mysql 将应用程序部署到 Heroku 时出错

Posted

技术标签:

【中文标题】使用 Tomcat 和 Mysql 将应用程序部署到 Heroku 时出错【英文标题】:Error deploying app to Heroku with Tomcat and Mysql 【发布时间】:2020-04-02 00:46:02 【问题描述】:

我有一个包含 4 个模块的 Maven 应用程序。我正在将该应用程序部署到 heroku。我使用 Tomcat 9.0.29,Java 8。本地一切正常,但 heroku 上有一个错误。问题是,我什至不知道它是什么。错误在哪里?有人可以帮助我吗?

2019-12-08T20:36:20.143115+00:00 app[web.1]: variable.
2019-12-08T20:36:20.143117+00:00 app[web.1]: --bind-on-init
2019-12-08T20:36:20.143119+00:00 app[web.1]: Controls when the socket used by the connector is bound. By default it
2019-12-08T20:36:20.143121+00:00 app[web.1]: is bound when the connector is initiated and unbound when the connector
2019-12-08T20:36:20.143123+00:00 app[web.1]: is destroyed., default value: true
2019-12-08T20:36:20.143125+00:00 app[web.1]: Default: true
2019-12-08T20:36:20.143126+00:00 app[web.1]: --compressable-mime-types
2019-12-08T20:36:20.143129+00:00 app[web.1]: Comma delimited list of mime types that will be compressed when using
2019-12-08T20:36:20.143131+00:00 app[web.1]: GZIP compression.
2019-12-08T20:36:20.143134+00:00 app[web.1]: Default: text/html,text/xml,text/plain,text/css,application/json,application/xml,text/javascript,application/javascript
2019-12-08T20:36:20.143136+00:00 app[web.1]: --context-xml
2019-12-08T20:36:20.143138+00:00 app[web.1]: The path to the context xml to use.
2019-12-08T20:36:20.143140+00:00 app[web.1]: --enable-basic-auth
2019-12-08T20:36:20.143142+00:00 app[web.1]: Secure the app with basic auth. Use with --basic-auth-user and
2019-12-08T20:36:20.143144+00:00 app[web.1]: --basic-auth-pw or --tomcat-users-location
2019-12-08T20:36:20.143146+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143148+00:00 app[web.1]: --enable-client-auth
2019-12-08T20:36:20.143150+00:00 app[web.1]: Specify -Djavax.net.ssl.keyStore and -Djavax.net.ssl.keyStorePassword in
2019-12-08T20:36:20.143151+00:00 app[web.1]: JAVA_OPTS
2019-12-08T20:36:20.143153+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143155+00:00 app[web.1]: --enable-compression
2019-12-08T20:36:20.143157+00:00 app[web.1]: Enable GZIP compression on responses
2019-12-08T20:36:20.143159+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143161+00:00 app[web.1]: --enable-naming
2019-12-08T20:36:20.143162+00:00 app[web.1]: Enables JNDI naming
2019-12-08T20:36:20.143165+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143166+00:00 app[web.1]: --enable-ssl
2019-12-08T20:36:20.143168+00:00 app[web.1]: Specify -Djavax.net.ssl.keyStore, -Djavax.net.ssl.keystoreStorePassword,
2019-12-08T20:36:20.143171+00:00 app[web.1]: -Djavax.net.ssl.trustStore and -Djavax.net.ssl.trustStorePassword in
2019-12-08T20:36:20.143173+00:00 app[web.1]: JAVA_OPTS. Note: should not be used if a reverse proxy is terminating
2019-12-08T20:36:20.143175+00:00 app[web.1]: SSL for you (such as on Heroku)
2019-12-08T20:36:20.143177+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143179+00:00 app[web.1]: --expand-war-file
2019-12-08T20:36:20.143181+00:00 app[web.1]: Expand the war file and set it as source
2019-12-08T20:36:20.143183+00:00 app[web.1]: Default: true
2019-12-08T20:36:20.143185+00:00 app[web.1]: --expanded-dir-name
2019-12-08T20:36:20.143187+00:00 app[web.1]: The name of the directory the WAR file will be expanded into.
2019-12-08T20:36:20.143189+00:00 app[web.1]: Default: expanded
2019-12-08T20:36:20.143191+00:00 app[web.1]: --help
2019-12-08T20:36:20.143193+00:00 app[web.1]:
2019-12-08T20:36:20.143195+00:00 app[web.1]: --max-threads
2019-12-08T20:36:20.143197+00:00 app[web.1]: Set the maximum number of worker threads
2019-12-08T20:36:20.143200+00:00 app[web.1]: Default: 0
2019-12-08T20:36:20.143202+00:00 app[web.1]: --memcached-transcoder-factory-class
2019-12-08T20:36:20.143204+00:00 app[web.1]: The class name of the factory that creates the transcoder to use for
2019-12-08T20:36:20.143206+00:00 app[web.1]: serializing/deserializing sessions to/from memcached.
2019-12-08T20:36:20.143208+00:00 app[web.1]: --path
2019-12-08T20:36:20.143210+00:00 app[web.1]: The context path
2019-12-08T20:36:20.143212+00:00 app[web.1]: Default: <empty string>
2019-12-08T20:36:20.143214+00:00 app[web.1]: --port
2019-12-08T20:36:20.143216+00:00 app[web.1]: The port that the server will accept http requests on.
2019-12-08T20:36:20.143218+00:00 app[web.1]: Default: 8080
2019-12-08T20:36:20.143220+00:00 app[web.1]: --proxy-base-url
2019-12-08T20:36:20.143222+00:00 app[web.1]: Set proxy URL if tomcat is running behind reverse proxy
2019-12-08T20:36:20.143224+00:00 app[web.1]: Default: <empty string>
2019-12-08T20:36:20.143226+00:00 app[web.1]: --scanBootstrapClassPath
2019-12-08T20:36:20.143228+00:00 app[web.1]: Set jar scanner scan bootstrap classpath.
2019-12-08T20:36:20.143230+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143232+00:00 app[web.1]: --session-store
2019-12-08T20:36:20.143234+00:00 app[web.1]: Session store to use (valid options are 'memcache' or 'redis')
2019-12-08T20:36:20.143236+00:00 app[web.1]: --session-store-ignore-pattern
2019-12-08T20:36:20.143238+00:00 app[web.1]: Request pattern to not track sessions for. Valid only with memcache
2019-12-08T20:36:20.143240+00:00 app[web.1]: session store. (default is '.*\.(png|gif|jpg|css|js)$'. Has no effect
2019-12-08T20:36:20.143241+00:00 app[web.1]: for 'redis')
2019-12-08T20:36:20.143244+00:00 app[web.1]: Default: .*\.(png|gif|jpg|css|js)$
2019-12-08T20:36:20.143246+00:00 app[web.1]: --session-store-locking-mode
2019-12-08T20:36:20.143247+00:00 app[web.1]: Session locking mode for use with memcache session store. (default is
2019-12-08T20:36:20.143249+00:00 app[web.1]: all. Has no effect for 'redis')
2019-12-08T20:36:20.143251+00:00 app[web.1]: Default: all
2019-12-08T20:36:20.143253+00:00 app[web.1]: --session-store-operation-timeout
2019-12-08T20:36:20.143255+00:00 app[web.1]: Operation timeout for the memcache session store. (default is 5000ms)
2019-12-08T20:36:20.143257+00:00 app[web.1]: Default: 5000
2019-12-08T20:36:20.143279+00:00 app[web.1]: --session-store-pool-size
2019-12-08T20:36:20.143283+00:00 app[web.1]: Pool size of the session store connections (default is 10. Has no effect
2019-12-08T20:36:20.143285+00:00 app[web.1]: for 'memcache')
2019-12-08T20:36:20.143287+00:00 app[web.1]: Default: 10
2019-12-08T20:36:20.143289+00:00 app[web.1]: --session-timeout
2019-12-08T20:36:20.143291+00:00 app[web.1]: The number of minutes of inactivity before a user's session is timed
2019-12-08T20:36:20.143293+00:00 app[web.1]: out.
2019-12-08T20:36:20.143295+00:00 app[web.1]: --shutdown-override
2019-12-08T20:36:20.143296+00:00 app[web.1]: Overrides the default behavior and casues Tomcat to ignore lifecycle
2019-12-08T20:36:20.143299+00:00 app[web.1]: failure events rather than shutting down when they occur.
2019-12-08T20:36:20.143300+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143303+00:00 app[web.1]: --temp-directory
2019-12-08T20:36:20.143304+00:00 app[web.1]: Define the temp directory, default value: ./target/tomcat.PORT
2019-12-08T20:36:20.143306+00:00 app[web.1]: --tomcat-users-location
2019-12-08T20:36:20.143308+00:00 app[web.1]: Location of the tomcat-users.xml file. (relative to the location of the
2019-12-08T20:36:20.143310+00:00 app[web.1]: webapp-runner jar file)
2019-12-08T20:36:20.143312+00:00 app[web.1]: --uri-encoding
2019-12-08T20:36:20.143314+00:00 app[web.1]: Set the URI encoding to be used for the Connector.
2019-12-08T20:36:20.143316+00:00 app[web.1]: --use-body-encoding-for-uri
2019-12-08T20:36:20.143325+00:00 app[web.1]: Set if the entity body encoding should be used for the URI.
2019-12-08T20:36:20.143327+00:00 app[web.1]: Default: false
2019-12-08T20:36:20.143329+00:00 app[web.1]: -A
2019-12-08T20:36:20.143331+00:00 app[web.1]: Allows setting HTTP connector attributes. For example: -Acompression=on
2019-12-08T20:36:20.143333+00:00 app[web.1]: Syntax: -Akey=value
2019-12-08T20:36:20.143335+00:00 app[web.1]: Default: 
2019-12-08T20:36:20.143336+00:00 app[web.1]:
2019-12-08T20:36:20.223662+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-08T20:36:20.204740+00:00 heroku[web.1]: Process exited with status 1

Procfile 取自 Heroku 网站 Heroku

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war'

Pom 文件

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com/jj</groupId>
    <artifactId>hi</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>common</module>
        <module>dao</module>
        <module>service</module>
        <module>web</module>
    </modules>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>copy</goal></goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>9.0.27.0</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
        <project.java.version>1.8</project.java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.10.19</version>
        <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.160</version>
        </dependency>
        <!-- Servlet API 4.0 for tomcat 9 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0-M1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>```

【问题讨论】:

【参考方案1】:

您看到的是 webapp-runner 的“帮助”输出。我认为这表明webapp-runner.jar 的参数不正确。

您的Procfile 命令末尾似乎有一个杂散的' 字符。您可能需要删除它。

【讨论】:

以上是关于使用 Tomcat 和 Mysql 将应用程序部署到 Heroku 时出错的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统——将web应用部署到tomcat服务器上

Centos7.3安装Tomcat和MySQL并部署JavaWeb应用

停止/重新部署时 Tomcat 7+ 内存泄漏。弹簧数据,JPA,休眠,MySQL

docker部署tomcat应用和MySQL数据库

性能测试二十六:环境部署之Mysql+Redis+Tomcat环境整合

部署web测试环境 jdk,tomcat,mysql