The Springframework control is used in the program (mainly to operate the database with mybatis-spring).
Using MAVEN to manage the build of your project, you now need to build a jar package that contains all the dependent jar packages and can be run using Java-jar [filename] at the command line.
1. Maven-assembly-plugin
At the very beginning, try using the Maven-assembly-plugin plugin, which is configured as follows:
<build> <plugins> <plugin> <groupid>org.apache.maven.plugins</ Groupid> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptorRefs> < ;d escriptorref>jar-with-dependencies</descriptorref> </descriptorRefs> <archive> <manifest> <MAINCLASS>MAIN</MAINCLASS&G T </manifest> </archive> </configuration> <executions& Gt <execution> <id>make-assembly</id> <phase>package< ;/phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> ; </plugins> </build>
However, after the command line was packaged with the MVN Package command, after running Java-jar, the error is as follows:
for namespace [http://Www.springframework.org/schema/context] class path resource [Javaprojectapplicationcontext.xml]
Google for a while, some people on the internet said this is a bug Assembly-plugin plugin, because it in the third party packaging is, for Meta-inf under the Spring.handlers,spring.schemas and so on several files with the same name covered.
It is recommended to use the Maven-shade-plugin plugin.
2.maven-shade-plugin Plug-in
The shade plugin can import all dependent packages into the final executable jar package. Depending on the content on the Web, the POM is set up as follows:
<build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupi D> <artifactId>maven-shade-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>pack Age</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <Transformer Implementation="Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.defonds.RsaEncryptor</mainClass> </transformer> <Transformer Implementation="Org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <Transformer Implementation="Org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> ;
However, after the implementation of the error, as follows:
inch " Main " for Manifest Main attributes
After the lookup, the reason is that some of the packages are repeated references, and after packing some more *. SF and other files, resulting in an error.
Solution, add the following code to the Pom.xml file:
<configuration> <filters> <filter> <artifact>*:* </artifact> < excludes> <exclude>meta-inf/*. Sf</exclude> <exclude>meta-inf/*. Dsa</exclude> <exclude>meta-inf/*. rsa</exclude> </excludes> </filter> </filters> </configuration >
MVN CLEAN;MVN package; Java-jar ... After that, everything works fine.
Tossing a lot of day, and finally moving forward asynchronously, mark.
MAVEN Package Spring Project