首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java应用程序部署Heroku

Java应用程序部署Heroku
EN

Stack Overflow用户
提问于 2018-03-23 07:47:47
回答 1查看 616关注 0票数 1

上一次我做了一些关于web服务的研究,这些服务可以提供我的Java应用程序的构建和部署。我找到了Heroku,这似乎还好,但我遇到了一些问题。

首先,我的应用程序使用Spring (而不是Spring ),我有基于java的手动注释配置,根本没有web.xml。那是关于圈套的。现在,当涉及到提到的错误时,我将Heroku与我的GitHub存储库连接起来,然后部署它。一切都很好,最后只有一个问题,如下所示:

代码语言:javascript
复制
2018-03-23T07:12:02.679019+00:00 app[web.1]: Error: Main method not found in class th.config.MyWebAppInitializer, please define the main method as:
2018-03-23T07:12:02.679037+00:00 app[web.1]: public static void main(String[] args)
2018-03-23T07:12:02.679150+00:00 app[web.1]: or a JavaFX application class must extend javafx.application.Application

显然,Heroku环境需要一个包含main方法的类,这个方法在我的应用程序中是不存在的,至少在我自己的代码中是不存在的,但是很可能是在类中运行servlet的某个地方,比如ServletInitializer之类的。我试图使用标志<skipMain>true</skipMain>标志,以跳过这一点,但没有任何运气。

这里我包含了我的pom.xml文件:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
....
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <skipMain>true</skipMain>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
            <executions>
                <execution>
                    <id>default-war</id>
                    <phase>prepare-package</phase>
                    <configuration>
                        <skipMain>true</skipMain>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy-dependencies</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.github.jsimone</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>7.0.22.3</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<groupId>webofficesuite</groupId>
<artifactId>webofficesuite</artifactId>
<version>1.0-SNAPSHOT</version>

<!-- SPRING COMPONENTS -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.13.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.13.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.3.13.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.13.RELEASE</version>
    </dependency>

    <!-- SPRING SECURITY -->
    <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>


    <!-- Spring ORM -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.3.13.RELEASE</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-dbcp</artifactId>
        <version>7.0.55</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-catalina</artifactId>
        <version>9.0.1</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/jstl/jstl -->
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

    ...Other dependencies

</dependencies>

我将感谢任何帮助或指导,以使我成功地部署我的应用程序。此外,我尝试了名为OpenShift的其他web服务,并设法将我的应用程序部署到那里,但我不喜欢远程连接到mysql数据库,所以我更喜欢Heroku解决方案。但是,如果有任何其他好的web服务主机,你会推荐我是开放的建议。唯一的要求是它不需要每月花费太多的钱,因为它不会是一个庞大的应用程序,需要大量的内核和内存。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-23 13:46:10

确保您的Procfile包含如下内容:

代码语言:javascript
复制
web: java -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

您可以在使用Webapp Runner部署基于Tomcat的Java Web应用程序上的Heroku文档中了解有关使用Webapp Runner的更多信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49444725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档