一个Maven插件引发的错误


翻到一个前些天同事发来的邮件,内容如下:

 INFO [XmlBeanDefinitionReader] (XmlBeanDefinitionReader.java:315) - Loading XML bean definitions from URL [jar:file:/home/eagle/work-project/code/work/logMonitor/bmp/bmp-mq-consumer/target/bmp-mq-consumer-0.0.1.jar!/spring/collect-config.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: URL [jar:file:/home/eagle/work-project/code/work/logMonitor/bmp/bmp-mq-consumer/target/bmp-mq-consumer-0.0.1.jar!/spring/collect-config.xml]

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:318)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)

就是一个普通的Maven工程,spring 文件中声明了一个bean,主类只调用一句代码:

ClassPathXmlApplicationContext application = new ClassPathXmlApplicationContext(
				"classpath*:spring/*.xml");
在eclipse中运行没有任何问题,但打包后再运行jar文件就会出现上述异常。

这段代码和配置是没有问题的,以至于找不出错误原因来。

我建了个简单的工程来模拟,发现也有这个现象,便关注了一下。

经排查也没发现任何问题,便检查了一下打包后的jar中class文件的md5,同仓库中jar包中的class文件比对了下,发现文件是不同的。


同事要求将工程所有文件连同依赖打包为一个jar文件,这是个很奇怪的要求,且不谈与模块化背道而驰,各种依赖混在一起,光版本冲突问题就极难有效解决。

至于打包为什么会导致依赖发生变化,是使用了一个maven插件导致:


				maven-assembly-plugin
				
					false
					
						jar-with-dependencies
					
					
						
							com.Main
						
					
				
				
					
						make-assembly
						package
						
							assembly
						
					
				
			

于是建议同事不要用这个插件了。这插件的古怪行为我就没兴趣追究了,将所有文件打包为一个jar,居然会有这种功能的插件,我怀疑是谁太无聊了才会写这么个东西


你可能感兴趣的:(工具)