2016-08-20 91 views
2

我對Maven & Heroku完全陌生。我正在嘗試瞭解RESTful Web服務。因此,我在JAX-RS &中創建了一個示例Web應用程序,將其部署在Heroku中。當我在本地Tomcat 8上運行它時,示例web應用程序運行完美。但是,當我嘗試在Heroku上打開相同的Web應用程序時,它會給我提供應用程序錯誤。在Heroku上運行maven項目給出應用程序錯誤

這是我所得到的,當我在localhost:8080

enter image description here

運行它,但是當我嘗試運行在this相同的Web應用程序,它給了我下面的錯誤

enter image description here

我很確定我錯過了什麼,但我無法弄清楚什麼。

以下是我的index.jsp

<html> 
<body> 
    <h2>Jersey RESTful Web Application!</h2> 
    <p><a href="webapi/myresource">Jersey resource</a> 
    <p>Visit <a href="http://jersey.java.net">Project Jersey website</a> 
    for more information on Jersey! 
</body> 
</html> 

Procfile

web: java $JAVA_OPTS -cp target/classes:target/dependency/* MyResource

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!-- This web.xml file is not required when using Servlet 3.0 container, 
    see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <servlet> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>jersey.config.server.provider.packages</param-name> 
      <param-value>org.auro.self.auromovieshelf</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Jersey Web Application</servlet-name> 
     <url-pattern>/webapi/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

的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>org.auro.self</groupId> 
    <artifactId>auromovieshelf</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>auromovieshelf</name> 

    <build> 
     <finalName>auromovieshelf</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>com.heroku.sdk</groupId> 
       <artifactId>heroku-maven-plugin</artifactId> 
       <version>1.0.3</version> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.glassfish.jersey</groupId> 
       <artifactId>jersey-bom</artifactId> 
       <version>${jersey.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-servlet-core</artifactId> 
      <!-- use the following artifactId if you don't need servlet 2.x compatibility --> 
      <!-- artifactId>jersey-container-servlet</artifactId --> 
     </dependency> 
     <!-- uncomment this to get JSON support 
     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-moxy</artifactId> 
     </dependency> 
     --> 
    </dependencies> 
    <properties> 
     <jersey.version>2.23.1</jersey.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
</project> 

最後,以下是我的項目結構

enter image description here

謝謝您的時間!

+0

服務器的錯誤日誌中找到coud幫助 – davidxxx

+0

運行' heroku ps:restart「和」heroku logs -t「並向我們顯示輸出 – codefinger

回答

1

我自己找到了解決方案。我忘記了webapp-runner插件添加到我的pom.xml

這裏的插件

<build> 
    ... 
    <plugins> 
     ... 
     <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.30.2</version> 
           <destFileName>webapp-runner.jar</destFileName> 
          </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

一個完整的一步一步的指導可以在this site

相關問題