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

查看:275
本文介绍了我可以在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中有一些东西, like:

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中,在包装下,我只是取消了所有的包, ,请确保依赖关系位于服务器上的正确文件夹中并进行上传。 Yey!没有更多的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天全站免登陆