Specify the outputDirectory output path through maven-jar-plugin
You can exclude certain configuration files. If there is no folder, it will be automatically created!
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <!-- 指定打包的jar包输出路径 --> <outputDirectory>D:\test</outputDirectory> <!--不打入jar包的文件类型或者路径 --> <excludes> <exclude>**/*.properties</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> <exclude>static/**</exclude> <exclude>templates/**</exclude> </excludes> </configuration> </plugin>
Specify the outputDirectory output path through maven-resources-plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <!--打成jar包后复制到的路径 --> <outputDirectory> D:\test1 </outputDirectory> <resources> <resource> <!--项目中的路径 --> <directory>src/main/resources/</directory> </resource> </resources> </configuration> </execution> <!--可配置多个提取复制路径只需要 “<id>”名字不一样即可 --> <execution> <id>copy-bulid</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory> D:\test2 </outputDirectory> <resources> <resource> <directory>target</directory> </resource> </resources> </configuration> </execution> </executions> </plugin>
Copy the jar package through maven-antrun-plugin
Maven has become the de facto build standard in the Java industry, but in some cases, it is still very convenient if you can use the Ant command.
With the maven-antrun-plugin plug-in, you can additionally execute Ant scripts when Maven is executed, as shown in the following configuration:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>install</id> <phase>install</phase> <configuration> <target> <echo message="*******************install*******************" /> <mkdir dir="${basedir}/target/classes" /> <copy todir="../target/commons" overwrite="true"> <fileset dir="${project.build.directory}" erroronmissingdir="false"> <include name="*.jar" /> </fileset> </copy> <move file="${project.build.directory}/xxxxxxx.jar" tofile="${project.build.directory}/xxx.jar" /> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>clean</id> <phase>clean</phase> <configuration> <target> <echo message="*******************clean*******************" /> <delete dir="target" /> <mkdir dir="${basedir}/target/classes" /> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
${basedir}
refers to the project root path
${project.build.directory}
refers to the directory where the target is located
${project.build.finalName}
refers to the jar package prefix name
Embed the build.xml file through maven-antrun-plugin
As shown in the following configuration:
Place build.xml in the project root path, use
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>install</id> <phase>install</phase> <configuration> <target> <property name="compile_classpath" refid="maven.compile.classpath" /> <property name="runtime_classpath" refid="maven.runtime.classpath" /> <property name="test_classpath" refid="maven.test.classpath" /> <property name="plugin_classpath" refid="maven.plugin.classpath" /> <ant antfile="${basedir}/build.xml"> <target name="test" /> </ant> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
Use distributionManagement to set the storage path
This method does not use a plug-in, but directly configures distributionManagement
Use the deploy command to deploy to the target folder. If there is no folder, it will be automatically created!
<distributionManagement> <repository> <id>localRepository</id> <url>file:D:/testRepository</url> </repository> </distributionManagement>
Extension: Use the maven-dependency-plugin plug-in to export dependent packages to the specified folder
This method is to output dependent packages to the specified path
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!-- 指定输出路径 --> <outputDirectory>D:\test2</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin>
The above is the detailed content of How to implement in Java how to place the jar package in the specified location after maven completes the jar package. For more information, please follow other related articles on the PHP Chinese website!