日期:2014-05-18  浏览次数:20874 次

tomcat发布web时如何指定自定义的lib路径?就是不想把lib放在web-inf\lib下,想换个路径。
如题,因为使用了多种框架,所以类库包很多,为了使目录结构清晰建立工程时将这些包分成许多目录分类存放,
比如...\myweb\web-inf\lib下又建立了许多子目录
...\myweb\web-inf\lib\struts\*.jar
...\myweb\web-inf\lib\hibernate\*.jar
...\myweb\web-inf\lib\spring\*.jar
在eclipse环境中使用没有问题,因为eclipse可以自定义库路径,但是运行web时tomcat就找不到这些类库了,因为
tomcat默认只寻找到web-inf\lib目录和自身的lib目录。
请问有什么办法可以让tomcat能找到我自定义的各个库路径?

------解决方案--------------------
不能改,这是 Servlet 规范所规定的!

The contents of the WEB-INF directory are:

? The /WEB-INF/web.xml deployment descriptor.
? The /WEB-INF/classes/ directory for servlet and utility classes. The classes in
this directory must be available to the application class loader.
? The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets,
beans, and other utility classes useful to the Web application. The Web application
class loader must be able to load classes from any of these archive
files.

The Web application class loader must load classes from the WEB-INF/ classes
directory first, and then from library JARs in the WEB-INF/lib directory. Also, any
requests from the client to access the resources in WEB-INF/ directory must be
returned with a SC_NOT_FOUND(404) response.

Ref. Java Servlet Specification Version 2.5, SRV.9.5 Directory Structure, p.66.