Failed to load main class while executing war

时间:2021-10-09 09:16:07

I build my project using maven and generated a *.war file with the following content structure:

我使用maven构建我的项目并生成一个* .war文件,其中包含以下内容结构:

META-INF
- maven
-- net.avedo.spozz
--- Spozz-Webservice
---- pom.properties
---- pom.xml
- MANIFEST.MF
WEB-INF
- classes
-- net
--- avedo
---- spozz
----- Spozz.class
----- models
------ ...
----- services
------ ...
-- psql-custom.properties
- lib
-- ...
- web.xml

If I now try to run the generated war file using java -jar spozz.war, I get the following error:

如果我现在尝试使用java -jar spozz.war运行生成的war文件,我会收到以下错误:

Error: Could not find or load main class net.avedo.spozz.Spozz

What did I wrong? Please find the Manifest file and the definition of the maven-war-plugin in the pom.xml below.

我错了什么?请在下面的pom.xml中找到Manifest文件和maven-war-plugin的定义。

MANIFEST.MF

Manifest-Version: 1.0
Built-By: awilhelm
Build-Jdk: 1.7.0_51
Class-Path: javax.servlet-api-3.1.0.jar jetty-webapp-9.1.3.v20140225.j
 ar jetty-xml-9.1.3.v20140225.jar jetty-servlet-9.1.3.v20140225.jar je
 tty-security-9.1.3.v20140225.jar jetty-server-9.1.3.v20140225.jar jet
 ty-servlets-9.1.3.v20140225.jar jetty-continuation-9.1.3.v20140225.ja
 r jetty-http-9.1.3.v20140225.jar jetty-io-9.1.3.v20140225.jar jetty-j
 sp-9.1.3.v20140225.jar jetty-schemas-3.1.M0.jar javax.servlet.jsp-api
 -2.3.1.jar javax.servlet.jsp-2.3.2.jar javax.servlet.jsp.jstl-1.2.0.v
 201105211821.jar javax.servlet.jsp.jstl-1.2.2.jar javax.el-3.0.0.jar 
 org.eclipse.jdt.core-3.8.2.v20130121.jar jetty-util-9.1.3.v20140225.j
 ar jettison-1.3.5.jar stax-api-1.0.1.jar resteasy-jaxrs-3.0.6.Final.j
 ar scannotation-1.0.3.jar javassist-3.12.1.GA.jar jboss-annotations-a
 pi_1.1_spec-1.0.1.Final.jar activation-1.1.jar jcip-annotations-1.0.j
 ar resteasy-client-3.0.6.Final.jar async-http-servlet-3.0-3.0.6.Final
 .jar jaxrs-api-3.0.6.Final.jar resteasy-servlet-initializer-3.0.6.Fin
 al.jar log4j-1.2.17.jar slf4j-api-1.7.6.jar slf4j-log4j12-1.7.6.jar c
 ommons-io-2.4.jar ormlite-jdbc-4.48.jar ormlite-core-4.48.jar
Created-By: Apache Maven 3.2.1
Main-Class: net.avedo.spozz.Spozz
Archiver-Version: Plexus Archiver

Extract from pom.xml

从pom.xml中提取

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven.war.plugin.version}</version>
    <configuration>
        <webXml>src\main\webapp\WEB-INF\web.xml</webXml>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>net.avedo.spozz.Spozz</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

2 个解决方案

#1


0  

The simplest way I know to launch a .war file as a Web application is with Jetty Runner:

我知道将.war文件作为Web应用程序启动的最简单方法是使用Jetty Runner:

  1. Download jetty-runner.jar
  2. Run java -jar jetty-runner.jar spozz.war
  3. 运行java -jar jetty-runner.jar spozz.war

  4. Access your Web application at localhost:8080
  5. 在localhost访问您的Web应用程序:8080

#2


0  

A normal jar file has its class files in the jar file root. Your class files are in WEB-INF\classes which is the normal position for a war (web application).

普通的jar文件在jar文件根目录中有其类文件。您的类文件位于WEB-INF \ classes中,这是战争(Web应用程序)的正常位置。

You could use the already mentioned jetty approach or relayout your archive file.

您可以使用已经提到的jetty方法或重新布局您的存档文件。

Jar
     Myclass.class
     Mymain.class
     META-INF
            manifest

But maybe you do not want an executable war. Then you have to create a Jar using maven.

但也许你不想要一场可执行的战争。然后你必须使用maven创建一个Jar。

#1


0  

The simplest way I know to launch a .war file as a Web application is with Jetty Runner:

我知道将.war文件作为Web应用程序启动的最简单方法是使用Jetty Runner:

  1. Download jetty-runner.jar
  2. Run java -jar jetty-runner.jar spozz.war
  3. 运行java -jar jetty-runner.jar spozz.war

  4. Access your Web application at localhost:8080
  5. 在localhost访问您的Web应用程序:8080

#2


0  

A normal jar file has its class files in the jar file root. Your class files are in WEB-INF\classes which is the normal position for a war (web application).

普通的jar文件在jar文件根目录中有其类文件。您的类文件位于WEB-INF \ classes中,这是战争(Web应用程序)的正常位置。

You could use the already mentioned jetty approach or relayout your archive file.

您可以使用已经提到的jetty方法或重新布局您的存档文件。

Jar
     Myclass.class
     Mymain.class
     META-INF
            manifest

But maybe you do not want an executable war. Then you have to create a Jar using maven.

但也许你不想要一场可执行的战争。然后你必须使用maven创建一个Jar。