Java – Why can’t Maven find a package located in another module/project?

Why can’t Maven find a package located in another module/project?… here is a solution to the problem.

Why can’t Maven find a package located in another module/project?

I’m trying to compile a multi-module Maven project. I’m having trouble compiling the new module I added. This problem occurs because a new module tries to import a pair of packages that exist in another module.

This is the pom .xml for the new module:

enter image description here
enter image description here

This is the View in eclipse’s project browser, where I highlighted the 2 packages I imported from the ServicioJMS class of the new module:

enter image description here
enter image description here

This is the error displayed on the command line after executing MVN Clean Package

enter image description here

As you can see below, I added the module in parent pom.xml:

enter image description here

So, I don’t know what I’m doing wrong here ¿Any thoughts?

Note: Eclipse resolves dependencies related to the import in question without problems.

Solution

I’m having a similar issue. Go to the library you depend on (in your ~/.m2/repository directory or in the library’s ./target directory) and locate the compiled library jar. List it using jar -tf and check if the missing class is listed directly in the jar.

If you use the Spring Boot Maven plugin or similar plugin in a library that you depend on, it will build a jar with a completely different structure, and the class will be hidden in the structure instead of being named directly in the jar. Eclipse understands this, but the Spring Boot loader does not decompress the Spring Boot Maven plug-in structure of the libraries in the dependencies, it only does this for the runnable jar that is executing.

If this is correct for you, then you can remove the offending build plugin from your library’s pom so that it’s just a library and not a runnable spring boot jar.

Related Problems and Solutions