'Issue in Maven dependency when calling external jar

I am facing an issue with the Maven packaging my project is

  1. Maven project called (A) that has two threads one will run Spring Boot App and one will run Normal java project
  2. Maven project called (B) with Normal java Code will have Pojo and Models classes used in all project
  3. Maven project called (C) with Normal java Code
  4. Maven Project Called (E) with Normal java code

To summarize the use of them

  1. (A),(C),(E) will use Models/Pojo Classes from (B), (B) is added as Dependency in their POM
  2. (A) will use Method from (C), (C) is added as Dependency in (A) POM
  3. (C) will Load class from (E) using Classloader and use a method

The issue here:

when the (C) project Load a class in (E) and try to use a method with Parameter class from (B) {RestConnection beans} throw

Exception in thread "Thread-9" java.lang.NoClassDefFoundError: B/beans/RestConnections
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at com.eska.module.execution.model.bo.ExecutionBo.openANDLoadAllJarsDest(ExecutionBo.java:468)
    at com.eska.module.execution.model.bo.ExecutionBo.getDestModelJarData(ExecutionBo.java:372)
    at com.eska.module.execution.model.service.impl.ExecutionServiceImpl.start(ExecutionServiceImpl.java:45)
    at com.eska.module.execution.MainExecution.MainExecution.main(MainExecution.java:94)
    at com.eska.med.provman.module.generation.model.bo.StartupThreadingPhases$InterruptableTask.run(StartupThreadingPhases.java:97)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: B/beans/RestConnections
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 9 more

Note: The Project works fine if I run it from eclipse, but when I try to use the Maven jars this issue happened

I tried to export Runnable jar from the eclipse (the Project is added in the build path), this issue didn't happen but the spring boot will not work.

Can anyone Help please?



Solution 1:[1]

My guess is that (B) is not on the classpath when you run your project. On the CLI you would need to add -cp <path to (B) jar>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 grekier