2010-03-30 94 views
1

我有一個運行在tomcat中的基於mavenized,多模塊彈簧(3.0.1)的應用程序。我試圖創建一個獨立的工具,我可以通過一個jar分發給用戶(這樣他們只需雙擊它),該工具捆綁在上述應用程序的一些模塊中。創建可插入彈簧應用程序的其他罐子的雙擊'超級'jar

我已經使用maven-shade-plugin來組裝這個罐子。如果我炸開jar,它看起來好像所有的依賴關係都在那裏,並且兩個spring元數據文件已經從所有單獨的spring jar中正確連接起來。應用程序運行,直到我試圖實例化一個ClassPathXmlApplicationContext。當用戶在應用程序中點擊一個按鈕,則執行下面的方法:

public void createAppContext() { 
    ClassPathXmlApplicationContext context = 
     new ClassPathXmlApplicationContext(springFiles); 
} 

「springFiles」的類聲明如下:

public final String[] springFiles = { "/applicationContext-beans.xml" }; 

當執行以下錯誤上述方法出現:

 
Exception in thread "Thread-8" java.lang.ArrayIndexOutOfBoundsException: 3350 
     at org.springframework.asm.ClassReader.(Unknown Source) 
     at org.springframework.asm.ClassReader.(Unknown Source) 
     at org.springframework.asm.ClassReader.(Unknown Source) 
     at org.springframework.core.type.classreading.SimpleMetadataReader.(SimpleMetadataReader.java:48) 
     at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) 
     at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:82) 
     at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76) 
     at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader.java:302) 
     at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:157) 
     at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:132) 
     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:584) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) 
     at com.mycompany.StandaloneTool$2.run(StandaloneTool.java:124) 

任何幫助將不勝感激!

+0

執行加載的任何bean是否嘗試通過註釋加載其他上下文? – 2010-03-30 17:41:02

回答

1

只是一個預感,但它可能是陰影插件覆蓋Spring爲配置文件中的命名空間使用的元數據。在shade插件的文檔中查看merging content of specific files,看它是否可以解決您的問題。

+0

是的。 .xsd文件,更具體地說 – 2010-03-31 07:15:18

1

春天元數據文件似乎被正確複製。出於這個特定原因,我開始使用maven-shade-plugin。 :)

我提高了春季日誌到TRACE,這揭示了一些更多的信息(我應該做到這一點開始,哎呀!)。我遇到了一堆例外情況,指出各種.class文件具有無效的Java幻數。

事實證明,問題出在我如何使用maven-dependency-plugin。我的意圖是拉動一個.zip工件,解壓縮它,並在生成資源階段將其內容複製到特定的生成目錄。一個潛在的問題是我無意中使用了「解壓縮依賴」這個目標,這個目標比我想要的更依賴(依賴最終maven-shade-plugin最終會捆綁)。但是,似乎最終解決該問題的是去除了工件項目屬性「output-directory」,其中我指定了一個名爲「generated-resources」的目錄。一旦我刪除這個屬性,一切都運行順利。

目前還不清楚爲什麼.class文件中的幻數被更改/損壞,但至少問題已解決。任何人對於實際發生的事情有任何想法?

感謝您的所有意見!

相關問題