2011-11-19 61 views
1

這非常奇怪,我在Eclipse中運行項目沒有問題,但如果運行 java -jar xxx.jar(導出到Runnable Jar)classpath resource [spring/config/BeanLocations.xml]無法打開,因爲它不存在

 
    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore 
    Exception: IOException parsing XML document from class path resource [spring/config/BeanLocations.xml]; 
    nested exception is java.io.FileNotFoundException: classpath resource [spring/config/BeanLocations.xml] cannot be opened because it does not exist 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea 
    nDefinitions(XmlBeanDefinitionReader.java:349) 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea 
    nDefinitions(XmlBeanDefinitionReader.java:310) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReade 
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReade 
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReade 
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) 
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReade 
    r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) 
      at org.springframework.context.support.AbstractXmlApplicationContext.loa 
    dBeanDefinitions(AbstractXmlApplicationContext.java:113) 
      at org.springframework.context.support.AbstractXmlApplicationContext.loa 
    dBeanDefinitions(AbstractXmlApplicationContext.java:80) 
      at org.springframework.context.support.AbstractRefreshableApplicationCon 
    text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123) 
      at org.springframework.context.support.AbstractApplicationContext.obtain 
    FreshBeanFactory(AbstractApplicationContext.java:422) 
      at org.springframework.context.support.AbstractApplicationContext.refres 
    h(AbstractApplicationContext.java:352) 
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) 
      at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) 
      at my.lincdoc.manager.ProposalManager.getAllProposalInfo(ProposalManager 
    .java:183) 
      at my.lincdoc.manager.ProposalManager.eliminateDuplicate(ProposalManager 
    .java:194) 
      at my.lincdoc.controller.ProposalController.RetrieveProposalForm(Proposa 
    lController.java:70) 
      at my.lincdoc.common.App.main(App.java:16) 
    Caused by: java.io.FileNotFoundException: class path resource [spring/config/Bea 
    nLocations.xml] cannot be opened because it does not exist 
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat 
    hResource.java:143) 
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea 
    nDefinitions(XmlBeanDefinitionReader.java:336) 
      ... 16 more 

我把BeanLocations.xml裏面的文件夾

ApplicationContext appContext = new ClassPathXmlApplicationContext("spring/config/BeanLocations.xml"); 
ProposalFormBo proposalFormBo = (ProposalFormBo) appContext.getBean("proposalBo"); 
+0

當你解壓縮jar文件時,你看到'spring/config/BeanLocations.xml'文件,其中'spring'文件夾從你解壓文件的位置開始? – Santosh

回答

1

確保你包括你的jar非類資源。解壓你的jar並確保文件在那裏(我敢打賭它不在那裏)。你需要調整你如何生成你的jar來包含它。

+0

我解壓縮jar並仔細檢查文件,在那裏。 – Jason

+0

我用Runnable Jar文件導出。我選擇將所需的庫解壓縮到生成的JAR選項中。我嘗試其他選項也失敗.. – Jason

+0

是spring/config/BeanLocations.xml的完整路徑嗎?如果是,請嘗試使用「/spring/config/BeanLocations.xml」(前面帶有斜槓)。 –

相關問題