- This topic has 3 replies, 2 voices, and was last updated 14 years, 2 months ago by davemeurer.
-
AuthorPosts
-
mitabMemberI have a spring application which uses component scanning and import of subsidiary context files into the main application context. While this application runs fine from within MyEclipse for Spring 8.6 when I export the project as an executable jar with the dependent libraries packaged, the beans are not found. For eg my main class has the following code
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {“applicationContext.xml”});
WIPListService wipListService = context.getBean(“WIPListService”, WIPListServiceImpl.class);
wipListService.generateEAODualRoleReport();In the application context file I have
<import resource=”classpath:ServiceContext.xml” />In the service context file I have
<context:component-scan base-package=”service”/>and in the service package my bean class is annotated as
@Service(“WIPListService”)
public class WIPListServiceImpl implements WIPListService {Similarly another bean which was referring to a bean gave an error till I actually defined the bean in the xml file.
Is there anything special I need to do while exporting the application to get it to work outside MyEcipse. I selected Export -> Runnable Jar File and package dependent libraries in jar files as the option and run the jar from the command prompt as java -jar <jarfilename>.jar
davemeurerMemberHello,
Would the Adding Classes to the JAR File’s Classpath tutorial help? It seems a couple folks had similar issues, and one of the comments was the spring jar needed to be outside the app jar: Deployment as a jar forum post
If that doesn’t help, please respond with the error messages you are seeing.
Kind regards,
Dave
mitabMemberHi,
Thanks for the information. Based on your reply that the spring and other jar files need to be outside the application jar I regenerated the jar this time selecting to create an executable jar file with the libary jar files placed in a sub folder. This option worked and is much easier than manually specifying all the dependent library jars externally.
Thank you so much for your help.
davemeurerMemberHello,
Glad to hear it! Thanks for replying and posting what worked.
Kind regards,
Dave -
AuthorPosts