简体   繁体   English

Context.xml中的相对路径

[英]Relative path in Context.xml

Is there a way to set a relative path to the docBase attribute in the context.xml of a web application, so it is outside of the appBase directory of the tomcat server instance? 有没有办法在Web应用程序的context.xml中设置docBase属性的相对路径,因此它位于tomcat服务器实例的appBase目录之外?

I would like to be able to share the context configuration between computers and have the app living in a directory, not a war file. 我希望能够在计算机之间共享上下文配置,并让应用程序存在于目录中,而不是war文件中。 That way i can compile the classes directly into that directory (in my project development directory) and have tomcat use these classes without any copying/packaging needed. 这样我就可以直接将类编译到该目录中(在我的项目开发目录中)并让tomcat使用这些类而无需任何复制/打包。

I am using the tomcat 8.0.0-RC5. 我使用的是tomcat 8.0.0-RC5。 My directory Layout is: 我的目录布局是:

/home/david/projects/frontend/web-content          <-- the static html files
/home/david/projects/frontend/web-content/WEB-INF  <-- the WEB-INF with the web.xml
/home/david/projects/tomcat                        <-- tomcat base directory
/home/david/projects/tomcat/Catalina/localhost     <-- holds the frontend.xml context configuration

I have tried 我试过了

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/frontend" docBase="../../frontend/web-content">
</Context>

but that did not work. 但那没用。 The whole path before /web-content seems to be ignored. / web-content之前的整个路径似乎被忽略了。 The log says: 日志说:

The main resource set specified [/home/david/projects/tomcat/webapps/web-content] is not valid

The Tomcat 8 documentation for the context container says: 上下文容器的Tomcat 8文档说:

You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host. 您可以为此目录或WAR文件指定绝对路径名,也可以指定相对于拥有主机的appBase目录的路径名。

Does relative here mean a strict subdirectory of appBase (no .. allowed)? 这里的亲属是指appBase的严格子目录(不允许)吗?

Setting an absolute path works without problems. 设置绝对路径可以正常工作。 The configuration 配置

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/frontend" docBase="/home/david/projects/frontend/web-content">
</Context>

works, but it is specific to my computer. 有效,但它特定于我的电脑。 So I cannot share the context configuration without modification anymore. 所以我不能再进行修改来共享上下文配置。

I could create a symbolic link inside the appBase directory of the tomcat server and let it point to the web-content folder of my application. 我可以在tomcat服务器的appBase目录中创建一个符号链接,让它指向我的应用程序的web-content文件夹。 This would work, but I would have different configurations (symbolic links) on linux and windows machines. 这可以工作,但我会在linux和Windows机器上有不同的配置(符号链接)。

Just taking only the last name of relative path names and ignoring the first parts is most likly a bug in tomcat. 只取相对路径名的姓氏而忽略第一部分最有可能是tomcat中的一个错误。 Relative path names should work or must throw errors. 相对路径名应该起作用或必须抛出错误。 But ignoring parts is bad. 但忽略零件是不好的。 A workaround could be using an absolute path name like this: <Context docBase="${catalina.home}/../www.war" 解决方法可能是使用这样的绝对路径名: <Context docBase="${catalina.home}/../www.war"

I just reading the changelog of Tomcat 8.0.15. 我只是阅读Tomcat 8.0.15的更改日志。 The bug should be fixed(!): "Correctly handle relative values for the docBase attribute of a Context." 应修复该错误(!):“正确处理Context的docBase属性的相对值。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM