Tomcat war在本地运行,但不在heroku上或通过webapp-runner运行

时间:2017-04-30 23:32:55

标签: tomcat heroku

我有一个非常简单的war文件,当手动复制到Tomcat的webapps文件夹时工作正常(如http://localhost:8080/helloworld-0.0.1-SNAPSHOT/rest/)。但是当部署到heroku(https://foobar.herokuapp.com/helloworld-0.0.1-SNAPSHOT/rest/)或在嵌入模式下尝试本地运行(同上的localhost链接)时,浏览器上的 404错误(请求的资源不可用)

java -jar target/dependency/webapp-runner.jar target/*.war

我尝试了heroku网站上记录的所有可能的部署:

  • CLI
  • Maven Plugin
  • 的webapp浇道

只是将战争复制到本地运行的tomcat服务器似乎是可行的。这是我的pom.xml

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tutorialacademy.rest</groupId>
    <artifactId>helloworld</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>helloworld Maven Webapp</name>
    <url>http://maven.apache.org</url>

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

    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.9</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>

        <plugins>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.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>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.github.jsimone</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>8.0.39.0</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>1.1.3</version>
                <configuration>
                    <appName>foobar</appName>
                </configuration>
            </plugin>
        </plugins>

    </build>

</project>

这是我的web.xml(关键部分):

<servlet>
        <servlet-name>helloworld</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.tutorialacademy.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>helloworld</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

0 个答案:

没有答案