最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java之maven打完jar包之后將jar包放到指定位置匯總

 更新時(shí)間:2023年04月11日 08:26:22   作者:前方一片光明  
這篇文章主要介紹了Java之maven打完jar包之后將jar包放到指定位置匯總,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

前言

maven打完jar包之后,默認(rèn)放置位置是target目錄

有時(shí)候項(xiàng)目需要,如何將jar包放置到指定的目錄呢?

方式一

通過maven-jar-plugin指定outputDirectory輸出路徑

可以排除某些配置文件,沒有文件夾的話會自動創(chuàng)建!

<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包后復(fù)制到的路徑 -->
?? ??? ??? ??? ?<outputDirectory>
?? ??? ??? ??? ??? ?D:\test1
?? ??? ??? ??? ?</outputDirectory>
?? ??? ??? ??? ?<resources>
?? ??? ??? ??? ??? ?<resource>
?? ??? ??? ??? ??? ??? ?<!--項(xiàng)目中的路徑 -->
?? ??? ??? ??? ??? ??? ?<directory>src/main/resources/</directory>
?? ??? ??? ??? ??? ?</resource>
?? ??? ??? ??? ?</resources>
?? ??? ??? ?</configuration>
?? ??? ?</execution>
?? ??? ?<!--可配置多個(gè)提取復(fù)制路徑只需要 “<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復(fù)制jar包

Maven已經(jīng)成為Java 工業(yè)領(lǐng)域事實(shí)上的構(gòu)建標(biāo)準(zhǔn),但在某些情況下,如果可以用Ant命令,還是很方便的。

借助 maven-antrun-plugin 插件,可以在Maven執(zhí)行時(shí),額外執(zhí)行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>

<execution>是可執(zhí)行命令,可以修改maven的命令執(zhí)行過程,下面的兩個(gè)execution是修改了install和clean;

<echo>是打印命令;

<mkdir>是創(chuàng)建文件夾命令;(文件夾里面沒有東西時(shí)好像不會創(chuàng)建出來)

<copy>是復(fù)制命令,其中todir是目標(biāo)文件夾,overwrite是覆蓋舊文件,<fileset dir="xxxx">是源文件,<include>是包含jar包;

<move>是移動文件或者修改名稱命令

<delete>是刪除命令;

  • ${basedir} 指的是 項(xiàng)目根路徑 
  • ${project.build.directory} 指的是 target所在目錄
  • ${project.build.finalName} 指的是 jar包前綴名

方式四

通過maven-antrun-plugin嵌入build.xml文件

如下列配置所示:

將build.xml放到項(xiàng)目根路徑下,使用<ant antfile="${basedir}/build.xml">嵌入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設(shè)置存放路徑

這種方式?jīng)]有通過插件,而是直接配置distributionManagement

使用deploy命令可以部署到目標(biāo)文件夾,沒有文件夾的話會自動創(chuàng)建!

<distributionManagement>
?? ?<repository>
?? ??? ?<id>localRepository</id>
?? ??? ?<url>file:D:/testRepository</url>
?? ?</repository>
</distributionManagement>

擴(kuò)展:使用maven-dependency-plugin 插件將依賴包導(dǎo)出到指定文件夾

這種方式是將依賴包輸出到指定路徑

<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>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • kaptcha驗(yàn)證碼組件使用簡介解析

    kaptcha驗(yàn)證碼組件使用簡介解析

    這篇文章主要介紹了kaptcha驗(yàn)證碼組件使用簡介解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • IDEA提示 add *** to custom tags問題及解決

    IDEA提示 add *** to custom tags問題及解決

    文章介紹了如何在文檔注釋中添加自定義注解(@xxx),并提供了添加和刪除注解的方法,總結(jié)了個(gè)人經(jīng)驗(yàn),希望對大家有所幫助
    2024-12-12
  • 基于@ComponentScan注解的使用詳解

    基于@ComponentScan注解的使用詳解

    這篇文章主要介紹了@ComponentScan注解的使用詳解,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • 三種Spring BeanName生成器,你了解嗎

    三種Spring BeanName生成器,你了解嗎

    無論我們是通過 XML 文件,還是 Java 代碼,亦或是包掃描的方式去注冊 Bean,都可以不設(shè)置BeanName,而Spring均會為之提供默認(rèn)的 beanName,本文我們就來看看 Spring 中三種處理不同情況的 beanName生成器吧
    2023-09-09
  • 詳談ThreadLocal-單例模式下高并發(fā)線程安全

    詳談ThreadLocal-單例模式下高并發(fā)線程安全

    這篇文章主要介紹了ThreadLocal-單例模式下高并發(fā)線程安全,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • 關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則

    關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則

    這篇文章主要介紹了關(guān)于弱引用WeakReference所引用的對象的回收規(guī)則,如果一個(gè)弱引用實(shí)例的成員變量referent引用了一個(gè)對象obj,那么就稱這個(gè)弱引用實(shí)例對obj的引用是弱引用,被一個(gè)弱引用實(shí)例引用的對象,稱為弱引用對象,需要的朋友可以參考下
    2023-09-09
  • SpringBoot封裝響應(yīng)數(shù)據(jù)實(shí)現(xiàn)過程詳解

    SpringBoot封裝響應(yīng)數(shù)據(jù)實(shí)現(xiàn)過程詳解

    這篇文章主要介紹了SpringBoot封裝響應(yīng)數(shù)據(jù)實(shí)現(xiàn)過程,SpringBoot響應(yīng)數(shù)據(jù)封裝是指在SpringBoot應(yīng)用程序中,將返回的數(shù)據(jù)進(jìn)行封裝,以便于前端頁面或其他客戶端使用,感興趣想要詳細(xì)了解可以參考下文
    2023-05-05
  • 解決運(yùn)行jar包出錯(cuò):ClassNotFoundException問題

    解決運(yùn)行jar包出錯(cuò):ClassNotFoundException問題

    這篇文章主要介紹了解決運(yùn)行jar包出錯(cuò):ClassNotFoundException問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 使用ServletInputStream()輸入流讀取圖片方式

    使用ServletInputStream()輸入流讀取圖片方式

    這篇文章主要介紹了使用ServletInputStream()輸入流讀取圖片方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • springboot 加載 META-INF/spring.factories方式

    springboot 加載 META-INF/spring.factories方式

    這篇文章主要介紹了springboot 加載 META-INF/spring.factories方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10

最新評論

朔州市| 漠河县| 东平县| 霍邱县| 新闻| 古田县| 高邮市| 炉霍县| 宣威市| 林周县| 博爱县| 万载县| 美姑县| 无为县| 临朐县| 稷山县| 平安县| 雅江县| 库车县| 天峻县| 曲阳县| 桦甸市| 富民县| 九台市| 宝坻区| 曲阜市| 罗平县| 惠安县| 渭源县| 洪江市| 左权县| 安徽省| 中超| 内丘县| 潼关县| 呼伦贝尔市| 龙川县| 揭西县| 滨州市| 滕州市| 米易县|