gpt4 book ai didi

java - Heroku无法实现主类

转载 作者:行者123 更新时间:2023-12-01 09:40:36 27 4
gpt4 key购买 nike

以下是我的 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>com.luckypants</groupId>
<artifactId>LuckyPants</artifactId>
<version>1.0-SNAPSHOT</version>
<name>LuckyPants</name>

<properties>
<tomcat.version>7.0.34</tomcat.version>
<jersey.version>1.8</jersey.version>
<target.version>1.7</target.version>
<appassembler.version>1.8</appassembler.version>
<source.version>1.7</source.version>
<mvn.compiler.version>3.0</mvn.compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId>
<version>${jersey.version}</version> </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.14</version>
</dependency>
<!-- if you are using Jersey client specific features without the server
side -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>

</dependencies>
<build>
<finalName>LuckyPants</finalName>
<plugins>
<!-- <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version>
<configuration> <warSourceDirectory>src/main/java/com</warSourceDirectory>
<webResources> <resource> <directory>WebContent</directory> </resource> </webResources>
</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>7.0.40.0</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>${appassembler.version}</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>launch.Main</mainClass>
<name>webapp</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

我的Procfile的内容是web: java %JAVA_OPTS% -cp target\classes;"target\classes\*" Main

但是当我在 heroku 中运行此代码时,它给出以下错误消息

Error: Could not find or load main class launch.Main 2016-07-20T14:22:59.864248+00:00 heroku[run.2063]: State changed from up to complete 2016-07-20T14:23:01.234275+00:00 heroku[web.1]: Process exited with status 1 2016-07-20T14:23:01.248600+00:00 heroku[web.1]: State changed from starting to crashed

但是Main.class在启动包中。

我该如何解决这个问题?

最佳答案

我在您的 pom.xmlProcfile 中看到了一些不同且相互冲突的内容。

  • 您正在包含 webapp-runner,它可能应该在 Procfile 中使用以下命令运行:java -jar target/dependency/webapp-runner.jar yourapp.war

  • 您正在使用 appassembler-maven-plugin 构建可执行 JAR 文件,其中包含主类 launch.Main

  • 您已将应用配置为使用 Procfile 中的主类 Main(无包名称)运行。

为了正确回答这个问题,我必须知道如何运行您的应用程序。您需要为我们回答以下问题:

  • 如何在本地运行该应用?
  • 您的Main 类是什么? (如果您不知道,这可能意味着您有一个 WAR 文件)。

如果您要部署 WAR 文件,则需要使用 webapp-runner 运行。

如果您正在运行主类,则需要在 Profilejava 命令中使用完全限定的类名称(即 launch.主要)。

关于java - Heroku无法实现主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38484058/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com