在不更改WAR文件的情况下将JAR添加到WAR的类路径中 [英] Add JAR to WAR's classpath without changing the WAR file

查看:130
本文介绍了在不更改WAR文件的情况下将JAR添加到WAR的类路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tomcat中部署WAR文件。另外我有一个JAR文件。

I deploy a WAR file in Tomcat. In addition I have a JAR file.

是否可以在不更改WAR文件的情况下使JAR文件中的类可用于WAR文件中的服务,或者是否已将其添加到WAR的WEB- INF / lib?

Is it possible to make the classes in the JAR file available to services in the WAR file without changing the WAR file, or does it have be added to the WAR's WEB-INF/lib?

我尝试将JAR添加到 lib / ,但它不起作用。 Spring在启动时失败了org.springframework.beans.factory.BeanCreationException»java.lang.NoClassDefFoundError。

I've tried adding the JAR to lib/, but it doesn't work. Spring fails with org.springframework.beans.factory.BeanCreationException » java.lang.NoClassDefFoundError upon startup.

编辑

我意识到我可能已经让自己成为一个无法解决的,在架构上难以解决的问题。事情就是这样:

I realized that I might have made myself an unsolvable and architectually ugly problem. Here's the thing:


  • WAR有一个引用< bean id =warServiceclass =com。 war.Service/>

  • 我的JAR有一个扩展com.war.Service的类com.mystuff.MyService

  • 我用< bean id =warServiceclass =com.mystuff.MyService/>
  • $ b $替换了bean引用b
  • Spring因java.lang.NoClassDefFoundError失败:com.war.Service

  • The WAR has a reference <bean id="warService" class="com.war.Service" />
  • My JAR has a class com.mystuff.MyService that extends com.war.Service
  • I have replaced the bean reference with <bean id="warService" class="com.mystuff.MyService" />
  • Spring fails with java.lang.NoClassDefFoundError: com.war.Service

推荐答案

或者您可以将它(您的jar文件)放在 lib 文件夹下的Tomcat根目录中。 Chk this out:

Or you could put it(your jar file) in your Tomcat root directory under lib folder. Chk this out :

http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

Per你的编辑


  1. 你的罐子有问题

  2. 你完全弄错了应用程序上下文中的限定类名称

我碰巧有 mysql-connector-java-5.0。我的 lib 文件夹中的8-bin jar。只是为了测试我把它放在我的应用程序上下文中:

I've happen to have mysql-connector-java-5.0.8-bin jar in my lib folder. And just for test I've put this in my application context :

<bean id="driver" class="com.mysql.jdbc.Driver" />

作为魅力,检查以上两种情况

Worked as charm, check those two cases above

这篇关于在不更改WAR文件的情况下将JAR添加到WAR的类路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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