简体   繁体   English

maven项目中的库项目中的ClassNotFoundException

[英]ClassNotFoundException in a library Project in a maven Project

In my maven Project in eclipse, I have added a normal Java- Project as a Library project (with Java- Build Path). 在我的Eclipse Maven项目中,我添加了一个普通的Java- Project作为库项目(带有Java-Build Path)。 This worked fine until I wrote a method in this Library project that makes use of org.apache.commons.codec.digest.DigestUtils . 在我在此Library项目中编写了一个使用org.apache.commons.codec.digest.DigestUtils的方法之前,这种方法一直很好。 I added this external library both with an "external jar" in the java buildpath properties of the library project and as a maven dependency: 我在库项目的java buildpath属性中添加了一个带有“外部jar”的外部库,并将其添加为maven依赖项:

<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.4</version>
</dependency>

in eclipse both projects show no errors, but when run it gives me an ClassNotFoundException in the library project (btw. if I use the exact same line of code in the source of the maven project, it works just fine) 在eclipse中,两个项目均未显示任何错误,但是在运行时,它在库项目中给了我ClassNotFoundException(顺便说一句,如果我在Maven项目的源代码中使用完全相同的代码行,则可以正常工作)

The maven project runs on a tomcat7-server. Maven项目在tomcat7服务器上运行。

Now my question is: how can I fix this? 现在我的问题是:我该如何解决? The Library project is used by other projects as well, so just copying the code into the Maven project would be a less favored solution. Library项目也被其他项目使用,因此仅将代码复制到Maven项目中将不是一个受欢迎的解决方案。

Thanks in advance! 提前致谢!

您需要在WEB-INF / lib文件夹中而不是在构建路径上使用此库(通用编解码器)。

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

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