透過maven-jar-plugin指定outputDirectory輸出路徑
可以排除某些設定文件,沒有資料夾的話會自動建立!
<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>
透過maven-resources-plugin指定outputDirectory輸出路徑
<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>
透過maven-antrun-plugin複製jar包
Maven已成為Java 工業領域事實上的建置標準,但在某些情況下,如果可以用Ant指令,還是很方便的。
借助maven-antrun-plugin 插件,可以在Maven執行時,額外執行Ant腳本如下列配置所示:
<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}
${project.build.directory}
${project.build.finalName} 指的是jar套件前綴名稱
方式四
#如下列設定所示:
將build.xml放到專案根路徑下,使用<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>
使用distributionManagement設定存放路徑
這種方式沒有通過插件,而是直接配置distributionManagement######使用deploy指令可以部署到目標資料夾,沒有資料夾的話會自動建立! ###<distributionManagement> <repository> <id>localRepository</id> <url>file:D:/testRepository</url> </repository> </distributionManagement>
<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>
以上是Java之怎麼實作maven打完jar包之後將jar包放到指定位置的詳細內容。更多資訊請關注PHP中文網其他相關文章!