Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 407
jamesdeath123 Avatar asked Oct 31 '22 12:10

jamesdeath123


1 Answers

Yes, there is one: Show up the contextual menu of the web project, go to the Maven tab and uncheck the Resolve dependencies from workspace projects option: In this way, Eclipse will not interfere in Maven's dependency resolution chain.

like image 83
Little Santi Avatar answered Nov 15 '22 03:11

Little Santi