91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java之怎么實現maven打完jar包之后將jar包放到指定位置

發布時間:2023-05-06 10:57:05 來源:億速云 閱讀:110 作者:iii 欄目:開發技術

這篇文章主要介紹“Java之怎么實現maven打完jar包之后將jar包放到指定位置”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Java之怎么實現maven打完jar包之后將jar包放到指定位置”文章能幫助大家解決問題。

方式一

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

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

<echo>是打印命令;

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

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

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

<delete>是刪除命令;

  • ${basedir} 指的是 項目根路徑 

  • ${project.build.directory} 指的是 target所在目錄

  • ${project.build.finalName} 指的是 jar包前綴名

方式四

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

如下列配置所示:

將build.xml放到項目根路徑下,使用<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設置存放路徑

這種方式沒有通過插件,而是直接配置distributionManagement

使用deploy命令可以部署到目標文件夾,沒有文件夾的話會自動創建!

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

擴展:使用maven-dependency-plugin 插件將依賴包導出到指定文件夾

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

<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包放到指定位置”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阿拉善左旗| 隆子县| 年辖:市辖区| 南乐县| 尖扎县| 顺义区| 北安市| 闻喜县| 北海市| 淳安县| 区。| 美姑县| 全南县| 金秀| 韶山市| 兰坪| 石台县| 望城县| 敖汉旗| 吉首市| 柳江县| 楚雄市| 峨山| 宁河县| 海门市| 凤台县| 固镇县| 通许县| 旌德县| 呼和浩特市| 赣州市| 临邑县| 图们市| 瑞安市| 临汾市| 尉犁县| 洪江市| 霸州市| 元朗区| 永泰县| 华亭县|