Skip to content
Advertisement

SPRING java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

It seems people have had similar problems, but on IDE’s. I am not using an IDE.

I installed Spring using a Maven dependency as you will see in my build.xml file.

I get the following stacktrace that says org.springframework.context is not found:

run-decouple:

JavaScript
JavaScript

BUILD SUCCESSFUL Total time: 4 seconds

Here is my client (java file: DecoupledDataReaderClient.java):

JavaScript

Here is my build.xml file with the spring dependency & classpath and xmlns to use MAVEN *EDIT: ADDED THE CLASSPATH TO RUN-DECOUPLE*

JavaScript

And lastly, here is my beans.xml file

JavaScript

If someone could help me with why it is not finding the class even though the spring dependency is in my build.xml (which downloaded successfully according to the output of build.xml) and with it in the classpath, I would greatly appreciate it.

Thanks in advance.

Advertisement

Answer

artifact:dependencies is storing the classpath for the Spring dependencies in the path dependency.classpath, and you’re using that when you compile:

JavaScript

However, when you run, you’re only including your compiled source in the classpath:

JavaScript

This means the Spring classes aren’t included.

Try including dependency.classpath as well:

JavaScript

Edit: Your run-decouple target is using jar: “When using the jar attribute, all classpath settings are ignored“. Switch to specifying the main class and the classpath, so you can include the dependencies:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement