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

查看:86
本文介绍了在不更改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 ="warService" class ="com.war.Service"/>
  • 我的JAR具有com.mystuff.MyService类,该类扩展了com.war.Service
  • 我用< bean id ="warService" class ="com.mystuff.MyService"/>
  • 替换了bean引用
  • Spring失败,并出现java.lang.NoClassDefFoundError:com.war.Service

推荐答案

也可以将其(您的jar文件)放在 lib 文件夹下的Tomcat根目录中.查一下这个:

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

根据您的修改

  1. 罐子出问题了
  2. 您在应用程序上下文中误认为了全限定类名

我的 lib 文件夹中恰好有 mysql-connector-java-5.0.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天全站免登陆