Fragmented found some articles, some feel good mess, their own tidy up
The following is the configuration in Pom.xml, there would have been a lot of dependency packages, in order not to let the configuration look very long, I deleted some dependencies in my own project introduced in the JAR package
1 <Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"2 xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">3 <modelversion>4.0.0</modelversion>4 5 <groupId>Com.test</groupId>6 <Artifactid>Spdbcraw</Artifactid>7 <Packaging>Jar</Packaging>8 <version>0.0.1-snapshot</version>9 <name>Spdbcraw</name>Ten One <Dependencies> A <Dependency> - <groupId>Log4j</groupId> - <Artifactid>Log4j</Artifactid> the <version>1.2.13</version> - </Dependency> - <Dependency> - <groupId>Org.slf4j</groupId> + <Artifactid>Slf4j-api</Artifactid> - <version>1.7.5</version> + </Dependency> A <Dependency> at <groupId>Org.slf4j</groupId> - <Artifactid>Slf4j-log4j12</Artifactid> - <version>1.7.5</version> - </Dependency> - </Dependencies> - in <Build> - <Plugins> to <plugin> + <groupId>Org.apache.maven.plugins</groupId> - <Artifactid>Maven-jar-plugin</Artifactid> the <Configuration> * <Archive> $ <Manifest> Panax Notoginseng <Addclasspath>True</Addclasspath> - <Classpathprefix>lib/</Classpathprefix> the <MainClass>Com.test.xpathutil.Main</MainClass> + </Manifest> A <manifestentries> the <Class-path>.</Class-path> + </manifestentries> - </Archive> $ </Configuration> $ </plugin> - <plugin> - <groupId>Org.apache.maven.plugins</groupId> the <Artifactid>Maven-dependency-plugin</Artifactid> - <executions> Wuyi <Execution> the <ID>Copy</ID> - <Phase>Install</Phase> Wu <Goals> - <goal>Copy-dependencies</goal> About </Goals> $ <Configuration> - <outputdirectory>Target/lib</outputdirectory> - </Configuration> - </Execution> A </executions> + </plugin> the </Plugins> - </Build> $ the </Project>
View Code
Then clean it up and pack it up in the install, and the first package might be a long time to download something
In the middle of the package, there may be some errors that can lead to a failure to pack, it is recommended that the JDK version is configured in the project, or that there are other dependencies on the parent.
Finally, when the package is successful, copy the jar file and a Lib folder under the target folder, create a new folder (name arbitrarily) on any of the disks in the computer, put the Lib folder and the jar package in the newly created folder, and enter it under Windows DOS command line:
Java-jar Test.jar
Can run successfully!
-----Supplement-----------------------------------------------------------------------------
Another possibility is that many people have a need:
Maven, by default, src/main/resources files and class files into the jar package, but there are many scenarios where the files under the resources need to be packaged outside the jar package. This modifies the files under the resources directory without having to re-hit the jar
Here is also the address for a compounding method: http://blog.csdn.net/su1322339466/article/details/52923806
Generate executable jar packages with maven (with dependencies)