Question:

Simple question: In Tomcat7, what's the difference between using extraResourcePaths and aliases to access an directory outside the application?

I can use either of these two server.xml snippets and they both seem to work. Both seem to load this URL successfully: http://localhost/app/images/box.jpg. Is there an advantage to using one over the other?

<Context docBase="Eclipse_Project" path="/app"
reloadable="true" source="org.eclipse.jst.j2ee.server:Eclipse_Project"
aliases="/images=D:\path\to\images"/>

or

<Context docBase="Eclipse_Project" path="/app"
reloadable="true" source="org.eclipse.jst.j2ee.server:Eclipse_Project">
<Resources className="org.apache.naming.resources.VirtualDirContext"
extraResourcePaths="/images=D:\path\to\images"/>
</Context>
Answer:

This is the result of having multiple different ways of pulling in resources that aren't part of a WAR or exploded directory. Frankly it is a mess long overdue a clean-up. The 'overlay' (or whatever it ends up being called) feature proposed for Servlet 3.1 (i.e. Tomcat 8) has prompted a major clean-up. All the current implementations will be unified into a single implementation. It isn't pretty though, and it is going to take a while to complete.

Aliases are treated as external to the web application resources. The DirContext checks aliases before it checks its internal resources. Hence when you request the real path you get the original.

If you use extraResourcePaths they are treated as part of the web application resources. It looks like Eclipse has triggered a copy of application resources to the work directory. This is usually done to avoid file locking. Since the extraResourcePaths are treated as part of the webapp, they get copied too and getRealPath() reports the copied location since that is where Tomcat is serving the resources from.



原文地址:http://stackoverflow.com/questions/11138701/difference-between-tomcats-extraresourcepaths-and-aliases-to-access-an-external

Difference between Tomcat's extraResourcePaths and aliases to access an external directory--转的更多相关文章

  1. Tomcat 开发web项目报Illegal access: this web application instance has been stopped already. Could not load [org.apache.commons.pool.impl.CursorableLinkedList$Cursor]. 错误

    开发Java web项目,在tomcat运行后报如下错误: Illegal access: this web application instance has been stopped already ...

  2. Tomcat启动时卡在“INFO: Deploying web application directory ”

    今天在linux上的tomcat部署一个网站时,在刚启动tomcat的时候提示启动成功,然后也能访问成功. 可是第二次启动时虽然没有报错,但无法访问tomcat,查看了catalina.out日志,发 ...

  3. Mac系统下安装Tomcat,以及终端出现No such file or directory的错误提示解决方案

    Tomcat,作为一个免费的服务器口碑实在太好,本想安装一个研究研究,无奈电脑是mac系统,在网上搜了一些安装方法总是出错,直到遇到了这篇博客,http://www.cnblogs.com/qingy ...

  4. 启动tomcat时,一直卡在Deploying web application directory这块的解决方案

    本来今天正常往服务器上扔一个tomcat 部署一个项目的, 最后再启动tomcat 的时候 发现项目一直都访问不了,看了一下日志: [root@iz8vbdzx7y7owm488t4d89z bin] ...

  5. 启动tomcat时,一直卡在Deploying web application directory

    本来今天正常往服务器上扔一个tomcat 部署一个项目的, 最后再启动tomcat 的时候 发现项目一直都访问不了,看了一下日志: 1 2 3 4 5 6 7 [root@iz8vbdzx7y7owm ...

  6. [转载]启动tomcat时,一直卡在Deploying web application directory这块的解决方案

    转载:https://www.cnblogs.com/mycifeng/p/6972446.html 本来今天正常往服务器上扔一个tomcat 部署一个项目的, 最后再启动tomcat 的时候 发现项 ...

  7. linux启动tomcat很久或者很慢Tomcat启动时卡在“INFO: Deploying web application directory ......”的解决方法

    解决方案: 找到jdk1.x.x_xx/jre/lib/security/java.security文件,在文件中找到securerandom.source这个设置项,将其改为: securerand ...

  8. Tomcat启动时卡在“INFO: Deploying web application directory ......”的解决方法

    https://blog.csdn.net/njchenyi/article/details/46641141

  9. Tomcat翻译--The Host Container

    原文:http://tomcat.apache.org/tomcat-7.0-doc/config/host.html Introduction(介绍) The Host element repres ...

随机推荐

  1. 你好,C++(5)如何输出数据到屏幕、从屏幕输入数据与读写文件?

    2.2  基本输入/输出流 听过HelloWorld.exe的自我介绍之后,大家已经知道了一个C++程序的任务就是描述数据和处理数据.这两大任务的对象都是数据,可现在的问题是,数据不可能无中生有地产生 ...

  2. openstack nova数据库计算结点IP地址

    最近遇到一个问题就是在控制结点上查找nova数据库中 select * from compute_nodes\G;中出现IP地址一直是127.0.0.1不是计算结点的IP,就算修改成计算结点的IP,也 ...

  3. IE8’s Substr() Bug

    IE8不支持substr()函数, 第一个参数为负数,比如:var index = id.substr(-1, 1);替代:var index = id.substr(id.length-1, 1);

  4. Redis学习 - 入门

    业精于勤,荒于嬉:行成于思,毁于随 -- 韩愈·<进学解>   因为工作中需要用到Redis,所以最近抽点时间看了一下,现在将学习的内容整理一下.   一.简介 1.Redis是什么? R ...

  5. ECharts 是一款开源

    ECharts

  6. lua学习-1

    最近打算学习quick cocos2dx,所以首先打算学习一下lua这门语言,Lua 是一个小巧的脚本语言,轻量级,便于扩展. Lua脚本基本的数据类型:nil.boolean.number.stri ...

  7. layer弹出标签层tab

    引入文件: <script type="text/javascript" src="layer/layer.min.js"></script& ...

  8. 关于几种常用的Adapter使用区别

    Adapter常用的实现类如下: 1.ArrayAdapter:简单.易用的Adapter,通常用于将数组或List集合的多个值包装成多个列表项. 2.SimpleAdapter:并不简单.功能强大的 ...

  9. raspberry pi 3 截图及查看

    RASPBIAN JESSIE WITH PIXEL Image with PIXEL desktop based on Debian Jessie Version:November 2016 Rel ...

  10. Solr4.8.0源码分析(17)之SolrCloud索引深入(4)

    Solr4.8.0源码分析(17)之SolrCloud索引深入(4) 前面几节以add为例已经介绍了solrcloud索引链建索引的三步过程,delete以及deletebyquery跟add过程大同 ...