我在 Tomcat 中自动解压 WAR 文件时遇到了问题。我的Host
描述符位于server.xml
( defaultHost="mp.org"
):
<Host name="mp.org" appBase="/var/www/mp/target/web/"
unpackWARs="true" autoDeploy="true" deployOnStartup="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
我的mp.xml
地址/opt/tomcat/conf/Catalina/mp.org
:
<Context>
path=""
docBase="/var/www/mp/target/web/"
debug="1"
reloadable="true"
distributable="true"
crossContext="false"
swallowOutput="true"
</Context>
Catalina.out
启动 Tomcat 后:
15-Aug-2018 12:23:48.155 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.10
15-Aug-2018 12:23:48.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 20 2018 17:32:21 UTC
15-Aug-2018 12:23:48.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.10.0
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.15.0-29-generic
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-oracle/jre
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_181-b13
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
15-Aug-2018 12:23:48.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /opt/tomcat
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /opt/tomcat
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.awt.headless=true
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.security.egd=file:/dev/./urandom
15-Aug-2018 12:23:48.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms512M
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024M
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+UseParallelGC
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
15-Aug-2018 12:23:48.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/opt/tomcat
15-Aug-2018 12:23:48.162 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/opt/tomcat
15-Aug-2018 12:23:48.162 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/opt/tomcat/temp
15-Aug-2018 12:23:48.162 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
15-Aug-2018 12:23:48.464 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
15-Aug-2018 12:23:48.508 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
15-Aug-2018 12:23:48.555 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
15-Aug-2018 12:23:48.559 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
15-Aug-2018 12:23:48.560 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1133 ms
15-Aug-2018 12:23:48.620 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
15-Aug-2018 12:23:48.620 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.10
15-Aug-2018 12:23:49.116 SEVERE [main] org.apache.catalina.valves.AccessLogValve.getLogFile Failed to create directory [/var/www/tui.org/tomcat_logs] for access logs
15-Aug-2018 12:23:49.117 SEVERE [main] org.apache.catalina.valves.AccessLogValve.getLogFile Failed to create directory [/var/www/tui.org/tomcat_logs] for access logs
15-Aug-2018 12:23:49.118 SEVERE [main] org.apache.catalina.valves.AccessLogValve.open Failed to open access log file [/var/www/tui.org/tomcat_logs/localhost_access_log.2018-08-15.txt]
java.io.FileNotFoundException: /var/www/tui.org/tomcat_logs/localhost_access_log.2018-08-15.txt (Нет такого файла или каталога)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at org.apache.catalina.valves.AccessLogValve.open(AccessLogValve.java:651)
at org.apache.catalina.valves.AccessLogValve.startInternal(AccessLogValve.java:685)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:179)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:963)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
15-Aug-2018 12:23:49.121 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/var/www/tui.org/servlet]
15-Aug-2018 12:23:49.153 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/var/www/tui.org/servlet] has finished in [31] ms
15-Aug-2018 12:23:49.156 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying deployment descriptor [/opt/tomcat/conf/Catalina/mp.org/mp.xml]
15-Aug-2018 12:23:49.167 SEVERE [main] org.apache.catalina.startup.ContextConfig.beforeStart Exception fixing docBase for context [/mp]
java.io.IOException: Unable to create the directory [/var/www/mp/target/web/mp]
at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:115)
at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:632)
at org.apache.catalina.startup.ContextConfig.beforeStart(ContextConfig.java:738)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:182)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:742)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:718)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:703)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1840)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:525)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:424)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1585)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:308)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:966)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
15-Aug-2018 12:23:49.232 INFO [main] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of deployment descriptor [/opt/tomcat/conf/Catalina/mp.org/mp.xml] has finished in [76] ms
15-Aug-2018 12:23:49.237 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
15-Aug-2018 12:23:49.306 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
15-Aug-2018 12:23:49.318 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 757 ms
此日志中tui.org
也有主机。与问题无关。
环境和项目结构:
Tomcat 主页:/opt/tomcat/
包含 WAR 的目录:/var/www/mp/target/web/
Tomcat 版本:9.0.10
操作系统:Ubuntu 18.04
问题:当我停止 Tomcat、重新打包 WAR 并启动 tomcat 时,什么都没有发生, WAR 文件仍然静止,没有新文件夹。我做错了什么?我考虑过权限问题。我还读到过,当我想自动解压 WAR 时,/var/www/mp/target/web/
我不应该设置描述符(为什么?)。Context
有权限:
/opt/tomcat/conf/Catalina/mp.org/ drwxr-xr-x 2 wcobalt wcobalt
/opt/tomcat/conf/Catalina/mp.org/mp.xml -rw-r--r-- 1 wcobalt wcobalt
/var/www/mp/target/web/ drwxrwxr-x 2 wcobalt wcobalt
/var/www/mp/target/web/mp.war -rw-rw-r-- 1 wcobalt wcobalt
先感谢您。
PS,抱歉我的英语不好。
答案1
根据日志,这是一个权限问题,java 进程无法创建目录/var/www/mp/target/web/mp
。请注意,为了能够创建该目录,进程需要访问路径上的每个目录,因此仅仅拥有路径中最后一个条目的写入权限是不够的:您至少需要拥有通往该路径的所有目录的执行权限。
/var/www/mp/target/web/
尝试使用用户一步一步地转到目录(所以cd /var
,cd web
等等)wcobalt
。我怀疑其中一个目录您无法访问。