4

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

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

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

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

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

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

在启动服务器并导航到等等www.myDomain.com之后,我从 Tomcat 读取及其变体中得到了库存错误消息。提供有用反馈的日志文件中没有例外。www.myDomain.com/ROOTwww.myDomain.com/index.jspThe requested resource (/ROOT/) is not available.

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

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

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

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)

编辑

感谢大家到目前为止的帮助。当我的服务器运行 Java 1.6.0_24 时,我在开发机器上降级到 Java 1.6。我还使用 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
4

3 回答 3

4

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

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

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

于 2013-09-22T20:55:30.857 回答
2

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

于 2013-09-22T20:51:49.097 回答
0
  1. 检查您的 Tomcat 服务器中安装的 Java 版本。如果你的服务器有 jdk 1.7 并且 webapp 是用 jdk1.8 开发的,那么它会给出这种错误。

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

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

于 2020-05-13T15:19:26.503 回答