2017-03-07 335 views
2

我想爲Heroku平臺配置Procfile文件以在本地運行應用程序。我正在嘗試運行基於Tomcat的Java Web應用程序。

在本教程中,他們說:

To build your app locally do this: 
Use the Git Bash application to open a command shell on Windows. 
$ mvn clean install 
$ heroku local web 

我在項目目錄和mvn clean install後,我收到

BUILD SUCCESS

問題是,當我運行:heroku local web 我收到[WARN] No ENV file found web.1 | Error: Could not find or load main class $JAVA_OPTS

我Procfile具有1行:

網:java的$ JAVA_OPTS罐子目標/依賴/ webapp的-runner.jar --port $ PORT目標/ *戰爭

我使用Windows。我在堆棧上看到一個post,他們說在Procfile中Windows上的代碼是不同的。它應該是這個樣子(我的創作):

網站:JAVA%JAVA_OPTS%的罐子目標\依賴性\ web應用程序,runner.jar --port%PORT%的目標*的.war

我必須在目標文件夾中創建一個名爲「依賴」的文件夾?因爲我的項目中沒有webbapp-runner.jar,我不明白我該怎麼做。

這裏是我的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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.rares</groupId> 
<artifactId>first-web-application</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 

<dependencies> 
    <dependency> 
     <groupId>com.github.jsimone</groupId> 
     <artifactId>webapp-runner</artifactId> 
     <version>8.5.11.2</version> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>4.3.6.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 
</dependencies> 

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.2</version> 
       <configuration> 
        <verbose>true</verbose> 
        <source>1.8</source> 
        <target>1.8</target> 
        <showWarnings>true</showWarnings> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId> 
       <version>2.2</version> 
       <configuration> 
        <path>/</path> 
        <contextReloadable>true</contextReloadable> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

我要補充webapp的亞軍作爲一個插件?

+0

你嘗試從同一職位的其他解決方案你分享?像'web:java%JAVA_OPTS%-cp target \ classes;「target \ dependency \ *」Main'。您可以按照[這](https://devcenter.heroku.com/articles/deploying-java#the-procfile) – nullpointer

+0

它是什麼,我的主類?我剛LoginController中的Java類和登錄服務..A類我控制器的方法 – ProgIsMetal

+0

@ProhIsMetal服務類應該是一個。理想情況下,您想從中啓動應用程序的類。 – nullpointer

回答

1

您需要的webapp亞軍添加到您的pom.xml這樣的:

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

然後你Procfile可以是這樣的:

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

而且你Procfile.windows可以看看(東西)是這樣的:請參閱Deploying Tomcat-based Java Web Applications with Webapp Runner

+0

請使用[插件UPTODATE版本(https://maven.apache.org/plugins/maven-dependency-plugin/)和不那麼古老的版本... – khmarbaise

+0

我必須定義什麼地方$ JAVA_OPTS? – ProgIsMetal

+0

當我運行:mvn包 我收到構建成功,並在java -jar目標/依賴項/ webapp-runner.jar目標/ *。war我收到:錯誤無法訪問jarfile目標/依賴項/ webapp-runner.jar – ProgIsMetal

1

因此,我讀了很多關於此錯誤+在Heroku上的教程的stackoverflow上的帖子,並沒有找到解決方案,但我做了一個改進。我讀this post並刪除了開始<pluginManagement>和結束<pluginManagement/>標記pom.xml和現在dependency目錄和webapp-runner-8.0.30.1.jar創建。 我的應用程序正在工作,因爲如果我用Tomcat在Eclipse中運行我的應用程序,我可以到localhost:8080/login並且我可以看到我的網站。 當我運行:

MVN包

我接收build succes之後,我在CMD運行

Java的罐子目標/依賴性/ web應用-runner.jar目標/ * .war

我收到:error invalid or corrupt jarfile target/dependency/webapp-runner.jar

這裏是我的Procfile:

網:java的$ JAVA_OPTS罐子目標/依賴/ webapp的-runner.jar --port $ PORT目標/ *戰爭

這裏是我的Procfile.windows:

網站:JAVA%JAVA_OPTS%的罐子目標\依賴性\ web應用程序,runner.jar --port%PORT%的目標*的.war

我的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/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.rares</groupId> 
<artifactId>first-web-application</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 

<dependencies> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>6.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>4.3.6.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.17</version> 
    </dependency> 
</dependencies> 

<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.2</version> 
       <configuration> 
        <verbose>true</verbose> 
        <source>1.8</source> 
        <target>1.8</target> 
        <showWarnings>true</showWarnings> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId> 
       <version>2.2</version> 
       <configuration> 
        <path>/</path> 
        <contextReloadable>true</contextReloadable> 
       </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.5.11.2</version> 
            <destFileName>webapp-runner.jar</destFileName> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
</build> 

相關問題