执行WAR文件时出错 [英] Error while executing WAR file

查看:353
本文介绍了执行WAR文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用maven插件为我的项目结构构建了一个war文件.现在,当我运行这个war文件时,出现了错误

I have used maven plugin to build a war file for my project structure. And now when I run this war file, I get the error

Error: Could not find or load main class com.abc.HelloWorld.App 

由于某种原因,当我检查war文件时,在WEB-INF/classes/com/abc/HelloWorld/

For some reason, when I check the war file, my main class is getting generated under WEB-INF/classes/com/abc/HelloWorld/

我尝试将类路径添加到Manifest.MF文件,但没有帮助.

I have tried added a classpath to Manifest.MF file, but it has not helped.

这是我用于创建war文件的maven插件.该项目还包含一个嵌入式码头服务器.

Here is my maven plugin for creating a war file. Also this project contains an embedded jetty server.

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.1.1</version>
  <configuration>
  <webXml>WebContent\WEB-INF\web.xml</webXml>
    <warName>${project.artifactId}-${project.version}</warName>              
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <mainClass>com.infor.HelloWorld.App</mainClass>
      </manifest>
    </archive>
    <overlays>
    <overlay>
     <id>com.abc.HelloWorld</id>    
     <type>jar</type>
    </overlay>
    </overlays>
  </configuration>
  <executions>
    <execution>
      <id>default-war</id>
      <phase>package</phase>
      <goals>
        <goal>war</goal>
      </goals>
    </execution>
  </executions>
</plugin>

我尝试了这个问题,但是它有没有帮助.

I have tried this question, but it has not helped.

推荐答案

WebApp WAR文件是打包为Web容器部署的专用jar文件.

WebApp WAR files are a specialized jar files packaged for Web Containers to deploy from.

您可以拥有一个自执行的war文件,但最终会得到一个具有JAR行为覆盖的WAR文件,以便META-INF/MANIFEST.MF及其Main-Class可以实例化Jetty,然后将其本身加载到Webapp中该服务器实例.

You can have a self-executing war file, but you'll wind up having a WAR file that has JAR behavior overlaid so that the META-INF/MANIFEST.MF and its Main-Class can instantiate Jetty, then load in the webapp itself into that Server instance.

看看以下由Jetty项目维护的项目.

Take a look at the following project maintained by the Jetty Project.

https://github.com/jetty-project/embedded-jetty-实战

在以下情况下要小心,

  • 将服务器类合并到WAR文件中,以确保webapp部署不会失败(服务器类路径和webapp类路径之间的类重叠).
  • 合并META-INF/services/个文件
  • 不要将过多的自我执行的Server内容暴露给HTTP客户端(不要让它们下载任何敏感内容!)-这可以通过将该启动的服务器部分放在/WEB-INF/中来实现.目录
  • 您不想让webapp(战争)启动者走动并了解服务器组件(这可能会导致双重初始化,一次是在服务器类加载器中,一次是在webapp类加载器中)
  • merging the Server classes into the WAR file to not make the webapp deployment fail (for overlapping classes between the server classpath and the webapp classpath).
  • merging META-INF/services/ files
  • not exposing too much of the Server side of the self-executable to HTTP clients (don't let them download anything sensitive!) - this can be accomplished by putting the server parts of this startup in the /WEB-INF/ directory
  • you don't want to have the webapp (war) startup walking and knowing about the server components (this can cause double initialization, once in the server classloader, and once again in the webapp classloader)

如该项目所述:

从自我执行WAR文件的角度来看,该项目应为那些研究嵌入式Jetty使用的人员提供基线.

This project should provide a baseline for those investigating the use of Embedded Jetty from the point of view of a Self Executing WAR file.

该项目包含4个主要部分:

The project has 4 main parts:

  • /thewebapp/-这是WAR文件,即webapp,它以其本机格式存在,带有普通的maven <packaging>war</packaging>,并且产生的工件只是一个(尚未)自执行的WAR文件
  • /theserver/-这是嵌入式Jetty服务器jetty.livewar.ServerMain.main(String args[]),您可以对其进行自定义以初始化Jetty服务器及其WebApp.您还可以在该项目中自定义JDBC服务器库,JNDI,日志记录等内容.此项目将生成一个uber-jar,其中包含运行服务器所需的所有依赖项. maven-shade-plugin会特别注意合并META-INF/services/文件.
  • /server-bootstrap/-它包含2个小类,它们根据实时WAR中的内容设置LiveWarClassLoader,然后从此新的ClassLoader运行jetty.livewar.ServerMain.main(String args[]).该项目还包含实时WAR需要/使用的实时META-INF/MANIFEST.MF
  • /livewar-assembly/-这是将上述3个项目链接到一个Live/Executable WAR文件中的项目.来自以上3个项目的工件由maven-assembly-plugin打包,并放置在将发挥最大作用(且安全)的位置.例如,将/theserver/中的服务器类放置在/WEB-INF/jetty-server/中,以使访问WAR文件的Web客户端无法访问它们.
  • /thewebapp/ - this is the WAR file, the webapp, as it exists in its native format, with normal maven <packaging>war</packaging> and a produced artifact that is just a WAR file that isn't (yet) self-executing.
  • /theserver/ - this is the Embedded Jetty Server jetty.livewar.ServerMain.main(String args[]) which you customize to initialize your Jetty server and its WebApp. This project also is the place where you customize for things like JDBC servers libraries, JNDI, logging, etc. This project produces a uber-jar with all of the dependencies needed to run the server. Special care is taken with the maven-shade-plugin to merge META-INF/services/ files.
  • /server-bootstrap/ - this contains 2 small classes that sets up a LiveWarClassLoader from the content in the live WAR and then runs jetty.livewar.ServerMain.main(String args[]) from this new ClassLoader. This project also contains the live META-INF/MANIFEST.MF that the live WAR will need/use
  • /livewar-assembly/ - this is the project that ties together the above 3 projects into a Live/Executable WAR file. The artifacts from from the above 3 projects are unpacked by the maven-assembly-plugin and put into place where they will be most functional (and safe). For example, the server classes from /theserver/ are placed in /WEB-INF/jetty-server/ to make them inaccessible from Web Clients accessing the WAR file.

注意:新组装的WAR文件中应该存在3个文件,如果使用此设置,则Web客户端可以将这些文件作为静态内容下载.

Note: there are 3 files present in your new assembled WAR file that you should be aware of, as these files can be downloaded by a Web Client as static content if you use this setup.

  • /jetty/bootstrap/JettyBootstrap.class
  • /jetty/bootstrap/LiveWarClassLoader.class
  • /META-INF/MANIFEST.MF
  • /jetty/bootstrap/JettyBootstrap.class
  • /jetty/bootstrap/LiveWarClassLoader.class
  • /META-INF/MANIFEST.MF

示例项目的设置方式应确保这些引导文件中存在的信息不应泄露有关您的服务器或其操作的私人或敏感信息.仅仅是Webapp可以作为实时/可执行WAR文件启动.

The example project is setup in such a way that information present in these bootstrap files should not reveal private or sensitive information about your Server or its operations. Merely that the Webapp can be started as a Live/Executable WAR file.

这篇关于执行WAR文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆