简体   繁体   English

将Maven存储库添加到Tomcat的类路径

[英]Add Maven repository to Tomcat's classpath

I'm working with Maven and Tomcat. 我正在使用Maven和Tomcat。 Some of the web applications I have to deploy use a lot of dependencies that are marked as "provided" in Maven. 我必须部署的某些Web应用程序使用了很多依赖关系,这些依赖关系在Maven中被标记为“提供”。 One example of these dependencies is spring-context . 这些依赖关系的一个例子是spring-context

So, when I package the project, those dependencies are not included in the lib folder of the WAR file. 因此,当我打包项目时,那些依赖项不包含在WAR文件的lib文件夹中。 Because of this, I'm getting 因此,我越来越

NoClassDefFoundError: org/springframework/context/ApplicationContext

I can't change the scope of the dependencies, and if possible, I don't want to include the dependencies JARs in the WAR file. 我无法更改依赖项的范围,并且如果可能的话,我不想在WAR文件中包含依赖项JAR。

How can I add the Maven repository as a classpath to Tomcat, so it can resolve all the "provided" dependencies? 如何将Maven存储库添加为Tomcat的类路径,以便它可以解决所有“提供的”依赖关系? Without copying the JARs to Tomcat's lib folder. 无需将JAR复制到Tomcat的lib文件夹。

I tried the shared.loader property in catalina.properties , but it doesn't work recursively: I have to add each JAR path to the property's value. 我在catalina.properties中尝试了shared.loader属性,但是它没有递归起作用:我必须将每个JAR路径添加到该属性的值中。

A dependency is marked as provided when the app server or container already has it, and you don't have to put it in the war. 当应用程序服务器或容器已经具有依赖项时,它将被标记为已提供,而您不必将其投入战争。 This is the case ie for the servlets jar, but not for the spring-context. 就是这种情况,例如,对于servlets jar,而对于spring-context则不是。 I think the better solution would be to mark this dependencies as "compile" instead of "provided". 我认为更好的解决方案是将此依赖项标记为“编译”而不是“提供”。

You have few options here. 您这里的选择很少。 Like @Andres said, you either add the JARs in the WAR or you add them to the classpath of Tomcat (ie lib folder). 就像@Andres所说的那样,您可以在WAR中添加JAR,也可以将它们添加到Tomcat的类路径(即lib文件夹)中。

While the concept of having a Maven-aware classloader is interesting, imagine all the possible jar version conflicts that could occur. 尽管具有支持Maven的类加载器的概念很有趣,但请想象一下可能发生的所有可能的jar版本冲突。 War A having a provided dependency on Lib v1.0.1 and War B having a provided dependency on Lib v2.1.0 , with Tomcat silently resolving these... War A具有对Lib v1.0.1的依赖关系,而War B具有对Lib v2.1.0的依赖关系,而Tomcat则静默地解决了这些问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM