We know that it is very common to use MAVEN to manage Java projects. For example, companies generally have their own Maven warehouse, through the MAVEN warehouse to solve our project dependencies, more convenient to build projects. But how do we generate jar packages and run them on Linux servers? What if a jar dependency is involved with some third parties? Now, write down my experiences and share them with you.
First, we want to export the code as a jar, this step, we can not take advantage of the Maven plugin to do, because if the MAVEN plugin to build the executable jar, need to configure, more cumbersome, you can directly take advantage of the export function of eclipse to generate the jar, and specify the main function to run.
Second, we need a maven-dependent jar package. Be aware that the jar packages specified in the Pom.xml are downloaded to the local. M2/repository, how do we get a dependent jar to put them all into the Lib directory? It is obviously not good to copy the jar package under the m2/repository. We can use MAVEN's commands to complete the copy jar package work. Here's how:
After entering the project's root directory, execute
MVN Dependency:copy-dependencies-doutputdirectory=target/lib
In this case, in the target directory, there is a Lib directory in the project required by the jar package is copied here.
Finally,java-djava.ext.dirs=./lib/-jar./xxx.jar
Because we are specifying the JAR option to run, we cannot use the CLASSPATH option to indicate the path to the third-party jar, because the classpath is invalid at this time. But we can use-djava.ext.dirs to make a simple designation.
This article is from the "Hard Struggle" blog, please make sure to keep this source http://zhangfengzhe.blog.51cto.com/8855103/1662451
How does the MAVEN project run under Linux?