无法找到或加载主类$ JAVA_OPTS

时间:2017-03-07 23:22:58

标签: java maven tomcat heroku

我正在尝试为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行:

  

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

我正在使用Windows。我在堆栈上看到post,他们说Procfile中Windows上的代码是不同的。它应该看起来像这样(我的创作):

  

web:java%JAVA_OPTS%-jar target \ dependency \ webapp-runner.jar   --port%PORT%target * .war

我必须在目标文件夹中创建一个名为“dependency”的文件夹?因为我的项目中没有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-runner添加为插件吗?

2 个答案:

答案 0 :(得分:1)

您需要像这样添加webapp-runner到您的 Sub MakeUnboldedTextBlue() ' ' MakeUnboldedTextBlue Macro ' ' Selection.Find.ClearFormatting Selection.Find.Font.Bold = False With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = True .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False .MatchControl = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Font.Color = 15773696 End Sub

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

答案 1 :(得分:1)

所以我在stackoverflow上阅读了很多有关Heroku的错误+教程的帖子,并没有找到解决方案,但我做了一些改进。我阅读了this post并删除了<pluginManagement>中的开始<pluginManagement/>和结束pom.xml标记,现在创建了dependency目录和webapp-runner-8.0.30.1.jar。 我的应用程序正在运行,因为如果我使用Tomcat在Eclipse中运行我的应用程序,我可以访问localhost:8080 / login,我可以看到我的网站。 我跑的时候:

  

mvn package

我收到build succes,然后我在cmd中运行

  

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

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

这是我的Procfile:

  

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

这是我的Procfile.windows:

  

web:java%JAVA_OPTS%-jar target \ dependency \ webapp-runner.jar --port%PORT%target * .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>