17

我想在 Tomcat 8 下对 JSP 目录进行符号链接。
它在 Tomcat 7 中以这种方式运行良好:

    <Context allowLinking="true">


但似乎 Tomcat 8 放弃了这个功能,它开始使用资源

http://tomcat.apache.org/migration-8.html#Web_application_resources)。

我的示例用法:

ROOT/jsp目录-->链接--> /var/tmp/realplaceofjspfiles/

一个糟糕的配置:

ROOT/META-INF/context.xml:

<Context>
   <Resources allowLinking="true">
         <PreResources className="org.apache.catalina.webresources.DirResourceSet"   base="/var/tmp/realplaceofjspfiles" internalPath="jspdirectory"/>
    </Resources>
</Context>

它为我放弃了这个例外:

    07-Mar-2014 04:09:12.113 WARNING [localhost-startStop-1] org.apache.tomcat.util.digester.SetPropertiesRule.begin [SetPropertiesRule]{Context/Resources/PreResources} Setting property 'internalPath' to 'jspdirectory' did not find a matching
     property.
    07-Mar-2014 04:09:12.114 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal 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:726)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
            at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1134)
            at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1780)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:744)
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@4756d5a0]
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
            at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4841)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4966)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
            ... 10 more
    Caused by: java.lang.NullPointerException
            at java.lang.String.startsWith(String.java:1392)
            at java.lang.String.startsWith(String.java:1421)
            at org.apache.catalina.webresources.DirResourceSet.list(DirResourceSet.java:115)
            at org.apache.catalina.webresources.StandardRoot.list(StandardRoot.java:129)
            at org.apache.catalina.webresources.StandardRoot.listResources(StandardRoot.java:313)
            at org.apache.catalina.webresources.StandardRoot.processWebInfLib(StandardRoot.java:523)
            at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:643)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
            ... 13 more

    07-Mar-2014 04:09:12.115 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory /PATH/apache-tomcat-8.0.3/webapps/ROOT
     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:729)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
            at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1134)
            at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1780)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:744)



我在这里看到了“内部路径”:http:
//tomcat.apache.org/tomcat-8.0-doc/config/resources.html

4

2 回答 2

29

要使 Tomcat 能够访问符号链接,请执行以下操作:

$CATALINA_HOME/conf/context.xml

雄猫 7

<Context allowLinking="true">
...

雄猫 8

<Context>
    <Resources allowLinking="true" />
...

不要在 WINDOWS(或任何其他不区分大小写的文件系统)上执行此操作,因为它会禁用区分大小写检查,允许 JSP 源代码泄露以及其他安全问题。

http://tomcat.apache.org/tomcat-8.0-doc/config/resources.html

于 2014-10-16T20:09:55.873 回答
2

看来您需要一个单独的“webAppMount”属性。

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
    <Resources>
        <PreResources
            className="org.apache.catalina.webresources.DirResourceSet"
            base="/FilePath/.../Resources"
            webAppMount="/resources"
            internalPath="/"/>
    </Resources>
 </Context>

这对我有用。它在我的网络应用程序的 META-INF/context.xml 中

于 2014-07-24T20:56:24.840 回答