我可以在 Tomcat 中为每个应用程序创建自定义类路径吗 [英] Can I create a custom classpath on a per application basis in Tomcat

查看:21
本文介绍了我可以在 Tomcat 中为每个应用程序创建自定义类路径吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些应用程序,我使用 ZK、其他 Hibernate、其他 Apache Commons 等.

For some applications I use ZK, others Hibernate, other Apache Commons, etc.

我不想部署 75MB 的 war 文件,只是因为它使用了很多库.

I don't want to deploy a 75MB war file, just because it uses lots of libraries.

我不想将库添加到我的 tomcat lib 文件夹,也不想将类路径添加到它的配置,因为我可能有一个使用库 x.1 的旧应用程序和另一个使用库 x.2 的应用程序

I don't want to add the libraries to my tomcat lib folder, or nor the classpath to it's configuration as I may have an old application using library x.1 and another application using library x.2

出于这个原因,最好在 web.xml 或 context.xml 中添加一些内容,例如:

For this reason, it would be great to have something in the web.xml or context.xml where I say something like:

<classpath>/usr/local/tomcat/custom-libs/zk-5.0.4</classpath>

注:以上为伪代码

推荐答案

从 Tomcat 7 开始,没有提到不能在生产中使用 VirtualWebappLoader.我试过了,它就像做梦一样.只需将以下内容添加到 META-INF/context.xml:

From Tomcat 7 there is no mention of not being able to use the VirtualWebappLoader in production. I tried it and it works like a dream. Simply add the following to META-INF/context.xml:

<?xml version="1.0" encoding="UTF-8"?>

<Context antiJARLocking="true" path="/websandbox">
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
          virtualClasspath="/usr/.../*.jar;/usr/.../*.jar"/>
</Context>

在 Netbeans 中,在打包下,我只是取消选中所有包,将 .war 大小减小到零,确保依赖项位于服务器上的正确文件夹中并上传.耶!不再有 100 MB 的 WAR 文件.

In Netbeans, under packaging, I just untick all the packages, taking the .war size down to nothing, make sure the dependencies are in the correct folders on the server and upload. Yey! No more 100 MB WAR file.

这篇关于我可以在 Tomcat 中为每个应用程序创建自定义类路径吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆