I have a spring class with main method. Inside the class am trying to read the values applicationContext.xml . My intention is to jar this main class along with its dependant jars,property files and applicationContext.xml .
But when i try to run the jar file via unix command prompt, it looks like the applicationContext file is not getting loaded.
The applicationContext.xml is seen inside the jar file and am able to see the sysouts inside my class.The code used to read the applicationContext.xml is
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath*:**/applicationContext.xml");
When i print context it is giving me the below message.
org.springframework.context.support.ClassPathXmlApplicationContext@89fbe3: start
up date [Mon Oct 01 15:07:43 IST 2012]; root of context hierarchy
When i try to print context.getBeanDefinitionCount() -- it gives me 0.
But am able to successfully excute this via eclipse . It is able able to read the applicationContext.xml and giving me the bean count as 13.
Not sure why it is not working when i run it as a jar.Please help me with your comments.
How did you get the .jar package? Did you use Eclipse export wizard? It's likely that you have put the "applicationContext.xml" in "/resources" folder. Make sure you fix the "Java Build Path" in Eclipse. Remove all the exclude tags that may be present on "/src/main/resources" folder. The resource folder should be considered a classpath, not just a folder with some xml files in the .jar package. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With