Technical point: Spring loads the XSD process:
http://blog.csdn.net/bluishglc/article/details/7596118
Background of the crime:
1. A common project using MAVEN management (vcenter-collector: About vcenter Data acquisition)
2, the main technology of the project: Java + MyBatis (based on interface form) + other
3, the project has a non-MAVEN warehouse jar package: Vijava (for vcenter Data acquisition), in the project to refer to the system mode
(The jar is placed under ${project.basedir}/lib)
Requirements: Package The project as an executable jar
After the incident:
1. The plugin (maven-assembly-plugin) that references maven has a dependent jar package
<plugin><artifactId>maven-assembly-plugin</artifactId><configuration><archive> <manifest><mainclass>com.main.vcentercollectmain</mainclass></manifest></archive ><descriptorrefs><descriptorref>jar-with-dependencies</descriptorref></descriptorrefs ></configuration></plugin>
Use the command: MVN clean assembly:assembly for packaging,
After the package runs: Java-jar Vcenter-collector.jar
Operation Error:
Org.springframework.beans.factory.parsing.BeanDefinitionParsingException:Configuration problem:unable to locate Spring Namespacehandler for XML schema namespace [Http://www.springframework.org/schema/context]
Then began to gather the answers on the Internet, the results of the surprise ah, found that the spring configuration file needs to be loaded with the relevant XSD mates, just do not understand the spring configuration file loading details, there is a post on Iteye:
Http://chenzhou123520.iteye.com/blog/1971322 explains the reason and gives the solution
OK, according to the post scheme selected the maven-shade-plugin plug-in, modify the configuration as follows:
<plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-shade-plugin</ Artifactid><version> 1.7.1</version><executions><execution><phase>package</ Phase><goals><goal>shade</goal></goals><configuration> <transformers> <transformerimplementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" > < mainclass>com.chenzhou.test.main</mainclass></transformer></transformers></ Configuration></execution></executions></plugin>
The main thing is to configure (merge all spring.schemas and spring.handlers files separately when packaging, so that they are not lost):
<transformers><transformerimplementation= " Org.apache.maven.plugins.shade.resource.AppendingTransformer "> <resource>meta-inf/spring.handlers</ Resource></transformer><transformerimplementation= " Org.apache.maven.plugins.shade.resource.AppendingTransformer "> <resource>meta-inf/spring.schemas</ Resource></transformer><transformer implementation= " Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer "><mainClass> Com.main.vcentercollectmain</mainclass></transformer></transformers>
This configuration means that the spring.handlers and Spring.schemas files are added to the build Jar package in append way.
OK, then pack: MVN Clean package, this next namespace problem solved, but the tiger to the Wolf Ah, there are new problems: Because the project uses MyBatis, and the interface form of development, the mapper files are all placed in the Java class directory, rather than the resource directory, as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7D/E0/wKioL1byE6_SYbRpAABe0tj28kU599.png "title=" configuration. png "alt=" Wkiol1bye6_sybrpaabe0tj28ku599.png "/>
As a result, when MAVEN is packaged, these XML files do not go in, and there is no way to introduce <resource> configuration:
<resource> <directory>src/main/java</ directory> <includes> <include>**/*.properties</include> <include>**/*. xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/ resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource>
OK, here's the mapper, the runtime goes wrong and the class is not found, which is exactly the local jar managed by the system:
<dependency><groupid>vijava</groupid><artifactid>vijava</artifactid><version >1.0</version><scope>system</scope><systempath>${project.basedir}/lib/ Vijava55b20130927.jar</systempath> </dependency>
Start Baidu again, find the answer, say is to use the <resource> configuration to specify the jar location, add the following configuration:
<resource> <targetPath>lib/</targetPath> <directory>lib/</directory> <includes > <include>**/vijava55b20130927.jar</include> </includes></resource>
Okay, pack mvn clean packages, the jar is in the jar package in a separate Lib directory, ready to run the jar to try, the result, error, said the class is not found, and this class is the class in Lib, it seems that although the system management package can be hit into the jar, But the operation is not quoted, it seems not ah, continue to find, find.
Some people say, install the jar to the local warehouse, I also want to ah, but, others get the project is not to be installed in their own local again, too much trouble, to take the ultimate solution:
Add in Project Repository, do not run on new machine mvn install:install-file command.
The configuration is as follows:
<repositories> <repository><id>in-project</id><name>in Project Repo</name> <url>file://${project.basedir}/lib</url> </repository></repositories><dependency> <groupId>vijava</groupId> <artifactId>vijava</artifactId> <version>1.0</version ></dependency>
This project is configured as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7D/E0/wKioL1byGKvTmBMoAABZ6yqxEt8729.png "title=" Sss.png "alt=" Wkiol1bygkvtmbmoaabz6yqxet8729.png "/>
Attention:
Your jar package and path must be in strict accordance with the format:/groupid/artifactid/version/artifactid-verion.jar in this example: lib/org/richard/my-jar/1.0/ The My-jar-1.0.jamaven-shade-plugin plugin has a configuration attribute: Createdependencyreducedpom, the default value is true. Note This property, if you use this plugin to deploy, or publish to a central warehouse this property will reduce your pom file, will you rely on <dependency> kill the correct way is to change this value to False, if true, will generate a cropped pom file: Dependency-reduced-pom.xml should change this value to false:<configuration> <createdependencyreducedpom>false</crea Tedependencyreducedpom> </configuration>
Finally, the complete configuration of POM for this project is given:
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/ Maven-4.0.0.xsd "><modelVersion>4.0.0</modelVersion><groupId>com.huhu</groupId>< Artifactid>vcentercollector</artifactid><version>0.0.1-snapshot</version><packaging >jar</packaging><name>vcentercollector</name><url>http://maven.apache.org</url ><repositories><repository> <id>in-project</id> <name>in project repo</name> <url>file://${ Project.basedir}/lib</url></repository></repositories><properties><spring.version >4.1.4.release</spring.version><mybatis.version>3.2.6</mybatis.version><slf4j.version >1.7.7</slf4j.version><log4j. version>1.2.17</log4j.version><project.build.sourceencoding>utf-8</ Project.build.sourceencoding></properties><dependencies><dependency><groupid>junit </groupid><artifactid>junit</artifactid><version>4.8</version><scope>test </scope></dependency><!-- spring --><dependency><groupId> org.springframework</groupid><artifactid>spring-core</artifactid><version>${ spring.version}</version></dependency><dependency><groupid>org.springframework</ Groupid><artifactid>spring-context</artifactid><version>${spring.version}</version> </dependency><dependency><groupId>org.springframework</groupId><artifactId> spring-webmvc</artifactid><version>${spring.version}</version></dependency>< Dependency><groupid>org.springframework</groupid><artifactid>spring-web</artifactid><version>${spring.version}</version></dependency>< Dependency><groupid>org.springframework</groupid><artifactid>spring-aop</artifactid ><version>${spring.version}</version></dependency><dependency><groupId> org.springframework</groupid><artifactid>spring-tx</artifactid><version>${ spring.version}</version></dependency><dependency><groupid>org.springframework</ Groupid><artifactid>spring-jdbc</artifactid><version>${spring.version}</version> </dependency><dependency><groupid>org.aspectj</groupid><artifactid>aspectjweaver </artifactId><version>1.8.5</version></dependency><!-- end spring -- ><!-- mybatis --><dependency><groupid>org.mybatis</groupid><artifactid >mybatis</artifactid><version>${mybatis.version}</version></dependency><dependency><groupid>org.mybatis</ groupid><artifactid>mybatis-spring</artifactid><version>1.2.2</version></ dependency><dependency><groupid>mysql</groupid><artifactid>mysql-connector-java< /artifactid><version>5.1.30</version></dependency><!-- Add Druid Connection Pool Pack --> <dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId>< version>1.0.12</version></dependency><dependency><groupid>dom4j</groupid>< Artifactid>dom4j</artifactid><version>1.6.1</version></dependency><dependency ><groupId>net.sf.json-lib</groupId><artifactId>json-lib</artifactId><version> 2.4</version><classifier>jdk15</classifier></dependency><dependency><groupid >commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency>< dependency><groupid>org.slf4j</groupid><artifactid>slf4j-log4j12</artifactid>< version>${slf4j.version}</version></dependency><dependency> < groupid>vijava</groupid> <artifactid>vijava</artifactid> <version>1.0</version></dependency></dependencies><build>< Finalname>vcentercollector</finalname><plugins><plugin><groupid> org.apache.maven.plugins</groupid><artifactid>maven-compiler-plugin</artifactid>< configuration><source>1.6</source><target>1.6</target></configuration></ Plugin><plugin><groupid>org.apache.maven.plugins</groupid><artifactid> maven-shade-plugin</artifactid><version> 1.7.1</version><executions><execution><phase>package</phase><goals><goal> shade</goal></goals><configuration><createdependencyreducedpom>false</ Createdependencyreducedpom><transformers><transformerimplementation= " Org.apache.maven.plugins.shade.resource.AppendingTransformer "><resource>meta-inf/spring.handlers</ Resource></transformer><transformerimplementation= " Org.apache.maven.plugins.shade.resource.AppendingTransformer "><resource>meta-inf/spring.schemas</ Resource></transformer><transformerimplementation= " Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer "><mainClass> Com.main.vcentercollectmain</mainclass></transformer></transformers></configuration> </execution></executions></plugin></plugins><resources><resource> <directory>src/main/java</directory> <includes> <include>**/*. properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering > </resource> <resource> <directory>src/main/resources</directory> <includes> < include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering> False</filtering> </resource ></resources></build></project>
Vcenter Data acquisition maven package executable jar blood history