[英]Including external jar in Tomcat ClassPath
In Tomcat I want to use a jar inside a web application. 在Tomcat中,我想在Web应用程序中使用jar。 The jar file will exist outside of the Tomcat directory.
jar文件将存在于Tomcat目录之外。
To include the jar file in tomcat classpath, I modified the TomcatHome/conf/catalina.properties to include the absolute path of my jar file like, 要在jarcat类路径中包含jar文件,我修改了TomcatHome / conf / catalina.properties以包含我的jar文件的绝对路径,如:
shared.loader=D:\jaa\MyJarFile.jar
as per the suggestion given in link, 根据链接中的建议,
http://www.mulesoft.com/tomcat-classpath
But it throws the error, 但它抛出了错误,
java.lang.NoClassDefFoundError
I have also tried , 我也尝试过,
shared.loader=D:\jaa\*.jar
shared.loader=file:\\D:\jaa\MyJarFile.jar
None of them seem to work :( 他们似乎都没有工作:(
If I try placing the jar inside tomcat/lib it seem to work. 如果我尝试将jar放在tomcat / lib中,它似乎工作。 But I am not allowed to do that.
但我不允许这样做。
Please help me out with this issue as I have implementation the next week.. 请帮助我解决这个问题,因为我已经在下周实施了..
I figured myself how to add the classpath for tomcat. 我想我自己如何为tomcat添加类路径。 Instead of editing catalina.properties, just create a "setenv.sh" in the Tomcat Bin directory with the classpath,
而不是编辑catalina.properties,只需使用类路径在Tomcat Bin目录中创建“setenv.sh”,
Example, 例,
CLASSPATH=D:\jaa\MyJarFile.jar
I just checked the catalina.sh in Tomcat/bin and these classpath variable will be set while setting the bootstrap as the classpath. 我刚刚检查了Tomcat / bin中的catalina.sh,并且在将引导程序设置为类路径时将设置这些classpath变量。
I was using IntelliJ and I tried everything like: 我使用的是IntelliJ,我尝试了以下所有方法:
mysql-connector.jar
. mysql-connector.jar
的依赖项。 Didn't work. mysql-connector.jar
to apache-home/lib/ folder. mysql-connector.jar
添加到apache-home / lib /文件夹。 Didn't work. mysql-connector.jar
from Maven inside IntelliJ. mysql-connector.jar
。 Just didn't work. The thing that worked for me : 对我有用的东西 :
Include the mysql-connector.jar
file in the PROJECT/web/WEB-INF/lib
folder. 在
PROJECT/web/WEB-INF/lib
文件夹中包含mysql-connector.jar
文件。
No need to add it as a dependency anywhere. 无需在任何地方将其添加为依赖项。 Just compile this and it will work fine.
只需编译它,它将正常工作。
I find myself copying extra JARs, which should be available for all contexts and should therefor go into the root loader, into the following directory: 我发现自己正在复制额外的JAR,这些JAR应该适用于所有上下文,并且应该进入根加载器,进入以下目录:
C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib
But this only possible if you have access to this directory, which might not be the case for all ISPs. 但这只有在您可以访问此目录时才有可能,这可能不是所有ISP的情况。 At least you can do it at home.
至少你可以在家里做。
Bye 再见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.