java apache-tomcat 6.0.20 中的共享 jars

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2099761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 19:26:12  来源:igfitidea点击:

Shared jars in apache-tomcat 6.0.20

javatomcatjava-web-start

提问by zbigh

I'm pretty new to JWS.

我对 JWS 很陌生。

I have a web application ( several web services ) that I want to deploy using tomcat 6.0.20 on a linux system.

我有一个 web 应用程序(几个 web 服务),我想在 linux 系统上使用 tomcat 6.0.20 进行部署。

Everything's ok if I generate a .war file with all used libraries inside and put it in the webapps directory, but I want to have these jars shared, and the .war file itself is way too big.

如果我生成一个包含所有使用过的库的 .war 文件并将其放在 webapps 目录中,一切都可以,但是我想共享这些 jar,而 .war 文件本身太大了。

First I tried the intuitive way - I created a link ( WEB-INF/lib ) to the directory containing the jars, but strangely it fails to deploy ( it starts if the directory is not a link ):

首先,我尝试了直观的方法 - 我创建了一个指向包含 jars 的目录的链接(WEB-INF/lib),但奇怪的是它无法部署(如果目录不是链接,它会启动):

SEVERE: Error configuring application listener of class com.sun.xml.ws.transport.http.servlet.WSServletContextListener
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3877)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

After that I created the $CATALINA_HOME/shared/lib directory, and moved the jars there ( I've deleted the WEB-INF/lib ) and it still displays the same error - it seems tomcat isn't looking for the jars anywhere else than the WEB-INF/lib directory. But on the other hand - why would creating a symbolic link make any difference?

之后我创建了 $CATALINA_HOME/shared/lib 目录,并将罐子移到那里(我已经删除了 WEB-INF/lib )它仍然显示相同的错误 - 似乎 tomcat 没有在其他任何地方寻找罐子比 WEB-INF/lib 目录。但另一方面 - 为什么创建符号链接会有什么不同?

My CATALINA_HOME and JRE_HOME vars seems to be right.

我的 CATALINA_HOME 和 JRE_HOME 变量似乎是正确的。

采纳答案by TofuBeer

Did you try putting the shared jar files in $CATALINA_HOME/lib? It says that ". Normally, application classes should NOT be placed here" but sounds like you would actually want to in your case.

您是否尝试将共享的 jar 文件放在$CATALINA_HOME/lib 中?它说“。通常,应用程序类不应该放在这里”,但听起来你实际上想要在你的情况下。

The $CATALINA_HOME/shared/lib seems to be gone in 6.0 (it was there in 5.5).

$CATALINA_HOME/shared/lib 似乎在 6.0 中消失了(它在 5.5 中存在)。

回答by Arnold Reuser

To add a bit more detail on this.

对此添加更多细节。

  • The metro project uses the shared class loader to make it possible to expose libraries to all webapps that you deploy.
  • The metro project uses the endorsed library mechanism of Tomcat to update your standard java distribution
  • Metro 项目使用共享类加载器来向您部署的所有 web 应用程序公开库。
  • Metro 项目使用 Tomcat 的背书库机制来更新您的标准 java 发行版

Shared Class loader

共享类加载器

Shared resources are shared across all web applications and not used by Tomcat internal classes.If Tomcat 6 requires a shared library. Adjust $CATALINA_HOME/conf/catalina.properties and set shared.loader=${catalina.home}/shared/lib/*.jar

共享资源在所有 Web 应用程序之间共享,并且不被 Tomcat 内部类使用。如果 Tomcat 6 需要共享库。调整 $CATALINA_HOME/conf/catalina.properties 并设置 shared.loader=${catalina.home}/shared/lib/*.jar

Endorsed libraries

认可的图书馆

To update the java platform and incorporate a new version of a given library, included in the standard distribution, one can add the library to /lib/endorsed or set the system wide property java.endorsed.dirs If Tomcat 6 requires an endorsed library. Several strategies can be used to incorporate the required endorsed library

要更新 java 平台并合并包含在标准发行版中的给定库的新版本,可以将库添加到 /lib/endorsed 或设置系统范围的属性 java.endorsed.dirs 如果 Tomcat 6 需要认可库。可以使用多种策略来合并所需的背书库

  • add the given library to java-home/lib/endorsed
  • set the Tomcat command line parameter -Djava.endorsed.dirs
  • use the default directory $CATALINA_HOME/endorsed; see /bin/setclasspath.sh or /bin/setclasspath.bat
  • set system wide parameter JAVA_ENDORSED_DIRS
  • 将给定的库添加到 java-home/lib/endorsed
  • 设置Tomcat命令行参数-Djava.endorsed.dirs
  • 使用默认目录 $CATALINA_HOME/endorsed;见 /bin/setclasspath.sh 或 /bin/setclasspath.bat
  • 设置系统范围的参数 JAVA_ENDORSED_DIRS

回答by Pascal Thivent

In Tomcat 6, the content of $CATALINA_HOME/libwill be made available to the "Common" class loader (see http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html). The shared/libdirectory that Tomcat 5.5 used to have no long exist.

在 Tomcat 6 中, 的内容$CATALINA_HOME/lib将提供给“ Common”类加载器(参见http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html)。shared/libTomcat 5.5 以前的目录已经不存在了。

However, I'd like to know what jars you are trying to put there exactly as the case of JAX-WS (or Metro) is "special". Also, what JDK are you using?

但是,我想知道您正试图将哪些罐子放在那里,因为 JAX-WS(或 Metro)的情况是“特殊的”。另外,你用的是什么JDK?

Update:As I said, the case of Metro is a bit special. To install it, copy webservices-rt.jar, webservices-tools.jar, webservices-extra.jar, webservices-extra-api.jar in $CATALINA_HOME/lib. But webservices-api.jar and jsr173_api.jar should go in $CATALINA_HOME/endorsed. Actually, this is what the metro-on-tomcat.xmlant script provided in the metro distribution does (and I would recommend to mimic it).

更新:正如我所说,Metro 的情况有点特殊。要安装它,请将 webservices-rt.jar、webservices-tools.jar、webservices-extra.jar、webservices-extra-api.jar 复制到$CATALINA_HOME/lib. 但是 webservices-api.jar 和 jsr173_api.jar 应该进去$CATALINA_HOME/endorsed。实际上,这就是metro-on-tomcat.xmlMetro 发行版中提供的ant 脚本所做的(我建议模仿它)。