Can a Tomcat docBase span multiple folders?-

系统 1822 0

Question:

I apologize if this is a poor question, but I'm using Windows and looking to see if there's a way to run a webapp via Tomcat where the  docBase  is multiple folders.

A little more background is that we have our Eclipse project set up in a way that the web content is broken into separate folders. One folder represents what our SDK provides, one is a folder which has SDK patches, and a third is the project-specific components -- either of the last two folders could have subfolders/files that "erase" items from the first two.

I'd like to try and have my context file point back into my dev environment so that I don't need to build/deploy in order to see the changes I'm making. Is this possible?

A couple other notes:

  • We thought about using symlinks via  mklink , but didn't want to create complexity if simplicity was out there.
  • This is just for running locally so simple hacks would be allowed. When we create the WAR which gets deployed to the real environment the ANT script creates a single web root.

 

Answer 1:

I use it this way:

    
          <Context docBase="jquery"                path="/js/jquery" />

    <Context docBase="foobar/www/javascript" path="/js" />

    <Context docBase="foobar/www/css"        path="/css" />

    <Context docBase="foobar"                path="/" />


    
  

Important for the concrete context is the path-attribute. A request is processed from top to bottom.

So a request for  /css/default.css  is only processed from the 3rd context.

A different order may catches a different context.

This is  wrong :

    
          <Context docBase="foobar"                path="/" />

    <Context docBase="jquery"                path="/js/jquery" />

    <Context docBase="foobar/www/javascript" path="/js" />

    <Context docBase="foobar/www/css"        path="/css" />


    
  

Because  /css/default.css  will be catched by the first context, not the fourth.

Edit 2013-08-10:  (Not by the answer-author) It is important to note that while the above technique will work, much of it is actually incorrect. Please see comments for details.

 

Answer 2:

Tomcat can do this for you, you just need a little extra configuration.

You are looking for  VirtualDirContext  which allows you to specify a list of  extraResourcePaths  which will be searched (in order) for additional files. You can use that to merge static resources, JSPs, directories of JAR files, etc.

Just remember that each path you add makes every file lookup potentially take longer -- especially if the file can't be found at all.

 

原文:http://stackoverflow.com/questions/17738049/can-a-tomcat-docbase-span-multiple-folders/17861223#17861223

 

Can a Tomcat docBase span multiple folders?--转


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论