Heroku无法找到或加载主类(但存在)

时间:2018-10-17 17:46:15

标签: java tomcat heroku

我已使用此工具在heroku上制作Java + tomcat Web应用程序,并且一切正常。 但是随后我使用了相同的示例来部署我的应用程序,并遇到了错误(找不到或加载主类Main)。

我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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>net.lim</groupId>
  <artifactId>eserver</artifactId>
  <version>0.01a</version>
  <packaging>war</packaging>

  <name>eserver Maven Webapp</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <tomcat.version>8.5.23</tomcat.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.1</version>
    </dependency>
    <!-- Jersey 2.19 -->
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet</artifactId>
      <version>2.19</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
      <version>2.19</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</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-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>eserver</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>8</source>
          <target>8</target>
        </configuration>
      </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>2.0.0</version>
            <configuration>
                <assembleDirectory>target</assembleDirectory>
                <programs>
                    <program>
                        <mainClass>Main</mainClass>
                    </program>
                </programs>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>
</project>

src文件夹

src/main/
src/main/java/
src/main/resources/
src/main/webapp/
src/main/java/Main.java
src/main/java/net/
src/main/java/net/lim/
src/main/java/net/lim/EServer.java
src/main/java/net/lim/model/
src/main/java/net/lim/services/
src/main/java/net/lim/model/Token.java
src/main/java/net/lim/services/AuthService.java
src/main/java/net/lim/services/RequestService.java
src/main/resources/credentials.json
src/main/webapp/admin.jsp
src/main/webapp/footer.css
src/main/webapp/login.jsp
src/main/webapp/WEB-INF/
src/main/webapp/WEB-INF/web.xml

Procfile:Web:sh target / bin / main 控制台输出:

$ heroku local
20:44:16 web.1   |  Error: Could not find or load main class Main
20:44:16 web.1   |  Caused by: java.lang.ClassNotFoundException: Main
[DONE] Killing all processes with signal  SIGINT
20:44:16 web.1   Exited with exit code null

缺少Main.class文件完全存在于目标/类的根目录中 这有什么问题吗?

1 个答案:

答案 0 :(得分:1)

找到原因,需要删除

<packaging>war</packaging>

来自pom.xml