Java 将我的 webapp 部署到 Tomcat7 时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18948394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 12:49:50  来源:igfitidea点击:

Trouble deploying my webapp to Tomcat7

javaeclipsejspmaventomcat7

提问by Mike Nitchie

This is my first effort deploying my own App to a remote tomcat server. I've searched and searched my problem and can't find a solution.

这是我第一次将自己的应用程序部署到远程 tomcat 服务器。我已经搜索并搜索了我的问题,但找不到解决方案。

I created a Maven project in eclipse with the webapparchetype. My local tomcat installation is listening on port 8080, but I have the tomcat installation on my server listening on `port 80'. I've completed and tested my app in Eclipse with Maven and Tomcat, and it works just fine.

我在 eclipse 中用webapp原型创建了一个 Maven 项目。我的本地 tomcat 安装正在侦听port 8080,但我的服务器上的 tomcat 安装正在侦听“端口 80”。我已经使用 Maven 和 Tomcat 在 Eclipse 中完成并测试了我的应用程序,它运行良好。

I exported my project to a .warfile and renamed it ROOT.war. Then, with the server stopped, I uploaded it into /var/lib/tomcat7/webapps/. Then I started the server and the .warfile autodeployed into the /var/lib/tomcat7/webapps/ROOT. When I navigated to www.myDomain.comI got a "link seems to be broken" error from Chrome, and a 404 status code.

我将我的项目导出到一个.war文件并将其重命名为ROOT.war. 然后,在服务器停止的情况下,我将其上传到/var/lib/tomcat7/webapps/. 然后我启动了服务器并将.war文件自动部署到/var/lib/tomcat7/webapps/ROOT. 当我导航到www.myDomain.comChrome 时,我收到了“链接似乎已损坏”错误和 404 状态代码。

I checked the logs and got this:

我检查了日志并得到了这个:

INFO: Deploying web application archive /var/lib/tomcat7/webapps/ROOT.war
Sep 22, 2013 6:31:06 PM org.apache.catalina.startup.ContextConfig init
SEVERE: Exception fixing docBase for context []
java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:131)
    at java.util.jar.JarFile.<init>(JarFile.java:150)
    at java.util.jar.JarFile.<init>(JarFile.java:87)
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:90)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:66)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:86)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:89)
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:112)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:697)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:820)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:363)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:401)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Sep 22, 2013 6:31:06 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Invalid or unreadable WAR file : error in opening zip file

I tried re-creating the .warfile and trying again, but with no luck. I read some articles explaining that this may be due to a corrupted war file (even though the file structure showed up on my server in full after restarting), so I decided to skip creating a .warfile completely. I created a copy of myWebappProjectthat I called ROOT. Then I just uploaded the ROOTdirectory in my workspace directly to .../webapps/ROOT.

我尝试重新创建.war文件并重试,但没有运气。我读了一些文章,解释说这可能是由于war文件损坏(即使重新启动后文件结构完整地显示在我的服务器上),所以我决定完全跳过创建.war文件。我创建了一个myWebappProject我称之为ROOT. 然后我只是将ROOT我工作区中的目录直接上传到.../webapps/ROOT.

After starting the server and navigating to www.myDomain.comand www.myDomain.com/ROOTand www.myDomain.com/index.jspetcetera etcetera I got the stock error message from Tomcat reading The requested resource (/ROOT/) is not available.and variations thereof. There were no exceptions in the log files that provided useful feedback.

启动服务器并导航到www.myDomain.comandwww.myDomain.com/ROOTwww.myDomain.com/index.jspetcetera etcetera 后,我从 Tomcat 读取The requested resource (/ROOT/) is not available.及其变体中收到了错误消息。日志文件中没有提供有用反馈的异常。

The directory structure that I'm using is the default for a Maven project with the webapp archetype.

我使用的目录结构是具有 webapp 原型的 Maven 项目的默认目录结构。

Thanks in advance for your help. Let me know if there is any other code or log files I can post.

在此先感谢您的帮助。如果我可以发布任何其他代码或日志文件,请告诉我。

EDITper @Aaron's recommendation, I tried unzipping the warfile myself and running again. More issues this time:

根据@Aaron 的建议进行编辑,我尝试自己解压缩战争文件并再次运行。这次的问题更多:

INFO: validateJarFile(/var/lib/tomcat7/webapps/ROOT/WEB-INF/lib/servlet-api-3.0-alpha-1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Sep 22, 2013 8:35:18 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component         [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.UnsupportedClassVersionError: uploadServlet/Uploader : Unsupported major.minor version 51.0 (unable to load class uploadServlet.Uploader)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1668)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:381)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:858)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

EDIT

编辑

Thanks everyone for the help so far. I downgraded to Java 1.6 on my development machine as my server is running Java 1.6.0_24. I also used Maven to create the .warfile via mvn package. I'm still getting a 404 and the 'broken link' error from Chrome. Here is the server start-up log.

感谢大家到目前为止的帮助。我在我的开发机器上降级到 Java 1.6,因为我的服务器运行的是 Java 1.6.0_24。我还使用 Maven.war通过mvn package. 我仍然收到来自 Chrome 的 404 和“链接断开”错误。这是服务器启动日志。

INFO: Deploying web application archive /var/lib/tomcat7/webapps/ROOT.war
Sep 22, 2013 9:45:53 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/ROOT/WEB-INF/lib/servlet-api-3.0-alpha-    1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class:    javax/servlet/Servlet.class
Sep 22, 2013 9:45:53 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component     [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.UnsupportedClassVersionError: uploadServlet/Uploader : Unsupported     major.minor version 51.0 (unable to load class uploadServlet.Uploader)
    at     org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
at     org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1668)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at  org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSe t.java:108)
    at  org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java: 58)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:381)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:858)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:345)
    at  org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more
Sep 22, 2013 9:45:53 PM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /var/lib/tomcat7/webapps/ROOT.war
java.lang.IllegalStateException: ContainerBase.addChild: start:     org.apache.catalina.LifecycleException: Failed to start component    [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Sep 22, 2013 9:45:53 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOTBackup
Sep 22, 2013 9:46:30 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took  [36,729] milliseconds.
Sep 22, 2013 9:46:30 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-80"]
Sep 22, 2013 9:46:30 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 37873 ms

采纳答案by Paaske

From your stacktrace, I see two things;

从您的堆栈跟踪中,我看到两件事;

  1. the servlet apiis included in your war-file. This is not allowed (by servlet spec), but it shouldn't prevent the app from starting. Try changing the <scope>to providedfor your servlet dependency in your pom.xml

  2. Minor / major version is wrong. This usually means that you have compiled for a newer Java version locally than what you have on your server. (e.g. compiling Java 7 locally and running Java 6 on the server). Try setting the source and target to the Java version you are running on the server in you pom.xml(maven-compiler-plugin)

  1. Servlet API的包含在你的战争文件。这是不允许的(根据 servlet 规范),但它不应阻止应用程序启动。尝试在您的 servlet 依赖项中更改<scope>toprovidedpom.xml

  2. 次要/主要版本是错误的。这通常意味着您在本地编译了比服务器上更新的 Java 版本。(例如,在本地编译 Java 7 并在服务器上运行 Java 6)。尝试将源和目标设置为您在您的服务器上运行的 Java 版本pom.xml( maven-compiler-plugin)

回答by NimChimpsky

Unsupported major minor version is one of the errors you building with one version of Java and deploying with another.

不支持的主要次要版本是您使用一个 Java 版本构建并使用另一个版本部署的错误之一。

回答by somspeaks

  1. check your java version installed in your tomcat server. if you server has jdk 1.7 and webapp is developed with jdk1.8 then it will give this kind of error.

  2. If point one is proper for you and still getting issue. check your dependencies in pom.xml. if you have incompatible dependency versions. then this error occurs.

  1. 检查您的tomcat服务器中安装的java版本。如果你的服务器有 jdk 1.7 并且 webapp 是用 jdk1.8 开发的,那么它会给出这种错误。

  2. 如果第一点适合您并且仍然遇到问题。检查 pom.xml 中的依赖项。如果您有不兼容的依赖版本。然后发生此错误。

https://www.youtube.com/watch?v=1jsKGhXmm4c

https://www.youtube.com/watch?v=1jsKGhXmm4c