1

I am getting the below error when running a simple Java project using Spring 5.

Error: Unable to initialize main class org.abhinash.javabrains.AopMain Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

Below is my main class

public class AopMain {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
        ShapeService shapeService = (ShapeService) ctx.getBean("shapes");
        System.out.println(shapeService.getCircle().getName());
    }
}

This is a simple Java project with no maven dependencies. I have added all the jars from spring 5 in my Classpath. Below is the screenshot from project explorer enter image description here Below is from my classpath enter image description here

I was only able to find answers related to this topic when the dependencies are added through maven. for example: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext maven

ClassNotFoundException for included dependency

Thanks in Advance!!

Abhinash Jha
  • 165
  • 1
  • 3
  • 17
  • If you run it outside of your IDE those jars aren't available. – M. Deinum Feb 23 '21 at 13:54
  • Time to switch to proper build tool like maven/gradle. – rkosegi Feb 23 '21 at 13:59
  • @M.Deinum I am running it through eclipse. Simple run as Java Application. – Abhinash Jha Feb 23 '21 at 14:15
  • @rkosegi i am following this tutorial https://www.youtube.com/watch?v=4-z-YsRfSF0&list=PLE37064DE302862F8&index=4 and so not using any build tool. It works there, and so want to know why is failing for me. – Abhinash Jha Feb 23 '21 at 14:15
  • Make sure when doing that that those libraries are also added to the classpath. It needs to be both available at build and runtime. Looks like the later is missing. Also following a tutorial which is 10 years old with newer library versions is a cause for things going wrong. – M. Deinum Feb 23 '21 at 14:26

0 Answers0