How to add an imported jar to the runtime classpath?

Answered

I have two projects: project A and project B. Project B is a web service deployed in a Tomcat 9 server. I want to use project A in project B, therefore I exported project A as a jar and imported it in project B. To do that I created a libs folder in the root path of project B, selected the jar and added it as a library. 

When using the imported project's classes I am getting no compilation errors; when launching the server neither. But at runtime I am getting NoClassDefFoundError exceptions when using project A's classes in project B.

To be honest I have never run into this kind of situations, but this is the first time I am importing a project of my own into another project of my own so I am not used to this.

How can I add my imported jar into the runtime classpath? I have been looking for information for quite a while but I couldn't find any help. I tried all this and it did not work.

3 comments
Comment actions Permalink

Make sure the new library jar that you have added to the module dependencies is also added to the artifact that is deployed on the server: http://www.jetbrains.com/idea/webhelp/configuring-artifacts.html.

0
Comment actions Permalink

I removed the old artifact and added it again. It seems the old one did not include the imported jar, but when adding it again it is included automatically. However I didn't remember what type of artifact there was at the beginning to I selected "Web Application: Exploded" and although Tomcat launches without errores, the routes are not working so I am getting 404 errors. Am I using the incorrect type or artifact?

0
Comment actions Permalink

Web Application: Exploded should work fine. Check if context is configured correctly.

0

Please sign in to leave a comment.