How to run MAVEN projects under the LINUXT system
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're going to export the code as a jar, this step, We can do this without using the Maven plugin, because if you take advantage of the Maven plugin, the executable jar needs to be configured and cumbersome, and you can export the jar directly using Eclipse's export function 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.
How to run MAVEN projects under the LINUXT system