简体   繁体   中英

project will treat maven dependency as a folder instead of a jar file and on run time gives ClassNotFoundError

In my maven project, I have this dependency which is my own project that is installed in my local maven (through cmd mvn install):

    <dependency>
        <groupId>com.myproject</groupId>
        <artifactId>api-core</artifactId>
        <version>1.0.0</version>
    </dependency>

However when I start the tomcat server, I will get ClassDefNotFoundError on the classes within this project.

I tried to add the jar to the deployment assembly through the project's properties, however when I add this jar file, it is taken as a folder and will always be placed into the Deploy path of "WEB-INF/lib/core.api.1.0.0.jar" which is then a folder inside the lib, therefore tomcat isn't able to locate the jar file. I also noticed in the Web Deployment Assembly, the Maven Dependencies are deployed to WEB-INF/lib. Apparently my own jar file is not considered Maven Dependencies when it is being deployed. When I further look into the Maven Dependencies from Eclipse, the jar file is packed inside as "core" folder and it is not treated as a jar file. Therefore on run time, the web app has trouble locating the jar file and is giving me complain.

Further investigation shows that in Eclipse, I have the core project imported, and Eclipse is "smart" to recognize that project is the one generating the dependency, and therefore automatically convert the jar to the folder. If I remove the core project, the maven dependencies will then successfully added as a jar file, and then the deployment to tomcat issue not problem at all!

So, my question is, is it a way to keep the dependency in folder structure, while I can still have to core project imported to my workspace?

是的,有一个:显示Web项目的上下文菜单,转到Maven选项卡并取消选中 Resolve dependencies from workspace projects选项:这样,Eclipse不会干扰Maven的依赖关系解析链。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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