欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用MAVEN打JAR包(直接使用)

 更新時(shí)間:2023年03月01日 11:09:11   作者:李秋  
這篇文章主要介紹了如何使用MAVEN打JAR包(直接使用),文中通過(guò)實(shí)例代碼介紹了maven?使用assembly插件進(jìn)行打包的方法,需要的朋友可以參考下

使用MAVEN打JAR包

一、簡(jiǎn)單的方法:

首先在pom.xml里面添加:

<build>  
    <plugins>  
      <plugin>  
        <artifactId>maven-assembly-plugin</artifactId>  
        <configuration>  
          <descriptorRefs>  
            <descriptorRef>jar-with-dependencies</descriptorRef>  
          </descriptorRefs> 
          <archive>  
            <manifest>  
              <mainClass>com.qunar.piao.data.integration.Boot</mainClass>  
            </manifest>  
            <!-- 需要執(zhí)行的main -->
          </archive>           
        </configuration>  
      </plugin>  
    </plugins>  
  </build>

然后執(zhí)行:mvn assembly:assembly 

最后執(zhí)行:java   -jar target/ticket-data-integration-0.0.1-SNAPSHOT-jar-with-dependencies.jar 

二、執(zhí)行任意main方法

兩個(gè)類,Boot類:

package com.qunar.check.integration;

public class Boot {

    public static void main(String[] args){
        System.out.println("test xingxing");
    }
}

Boot2類:

package com.qunar.check.integration;

public class Boot2 {
    public static void main(String[] args){
        System.out.println("test liqiu");
    }
}

那么執(zhí)行:

$ java -classpath target/check-jar-with-dependencies.jar com.qunar.check.integration.Boot2
test liqiu
$ java -classpath target/check-jar-with-dependencies.jar com.qunar.check.integration.Boot
test xingxing

兩個(gè)main函數(shù)都可以執(zhí)行

續(xù):

如果你的項(xiàng)目包含Spring,那么打包可能就會(huì)遇到的麻煩,可以參考:

http://www.dbjr.com.cn/article/276778.htm

擴(kuò)展:maven 使用assembly 進(jìn)行打包

1. pom 中添加assembly 插件

要使用assembly 進(jìn)項(xiàng)編譯打包, 首先主要在pom 中的build中添加插件信息, 具體如圖下所示:

<build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>${profile.dir}</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <!-- compiler插件參數(shù)設(shè)置,指定編碼 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>

        <!--   這個(gè)插件是關(guān)鍵   -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <!--   這個(gè)是assembly 所在位置  -->
                <descriptor>src/main/assembly/assembly.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2. 創(chuàng)建assembly文件夾和assembly.xml文件

創(chuàng)建assembly文件夾和assembly.xml文件, 這個(gè)樣子創(chuàng)建主要是規(guī)范。
在pom 中已經(jīng)介紹assembly.xml 位置。

<!--   這個(gè)是assembly 所在位置  -->
<descriptor>src/main/assembly/assembly.xml</descriptor>

創(chuàng)建assembly.xml 文件后添加如下內(nèi)容:

<assembly>
    <formats>
        <!--支持 zip,tar,tar.gz,tar.bz2,jar,dir,war 等 -->
        <format>tar.gz</format>
        <format>zip</format>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>conf</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
        <fileSet>
            <directory>${profile.dir}</directory>
            <outputDirectory>conf</outputDirectory>
            <!-- 表示的是包含下面格式的資源文件 -->
            <includes>
                <include>*.xml</include>
                <include>*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
            <fileMode>0644</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/assembly/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

fileMode 官方解釋:

Similar to a UNIX permission, sets the file mode of the files included. THIS IS AN OCTAL VALUE. Format: (User)(Group)(Other) where each component is a sum of Read = 4, Write = 2, and Execute = 1. For example, the value 0644 translates to User read-write, Group and Other

上述的三個(gè)fileSet 分別是將resource 下的資源打包到config 目錄下, 將assembly下的bin 啟動(dòng)相關(guān)腳本打包到bin 目錄下, 將maven項(xiàng)目依賴的所有jar 包, 打包到lib 中。
具體結(jié)構(gòu)如下圖所示:

這里寫圖片描述

參考地址:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

到此這篇關(guān)于如何使用MAVEN打JAR包(直接使用)的文章就介紹到這了,更多相關(guān)maven打jar包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring Boot  Excel文件導(dǎo)出下載實(shí)現(xiàn)代碼

    Spring Boot Excel文件導(dǎo)出下載實(shí)現(xiàn)代碼

    這篇文章帶領(lǐng)我們直接實(shí)現(xiàn)Excel文件的直接導(dǎo)出下載,后續(xù)開(kāi)發(fā)不需要開(kāi)發(fā)很多代碼,直接繼承已經(jīng)寫好的代碼,增加一個(gè)Xml配置就可以直接導(dǎo)出。具體實(shí)現(xiàn)代碼大家跟隨小編一起通過(guò)本文學(xué)習(xí)吧
    2018-11-11
  • Mybatis懶加載的實(shí)現(xiàn)

    Mybatis懶加載的實(shí)現(xiàn)

    這篇文章主要介紹了Mybatis懶加載的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Java實(shí)現(xiàn)每日給女友微信發(fā)送早安信息

    Java實(shí)現(xiàn)每日給女友微信發(fā)送早安信息

    這篇文章主要為大家詳細(xì)介紹了Java如何實(shí)現(xiàn)每日給女友微信發(fā)送早安等微信信息,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以了解一下
    2022-12-12
  • Java爬蟲抓取視頻網(wǎng)站下載鏈接

    Java爬蟲抓取視頻網(wǎng)站下載鏈接

    本文是通過(guò)JAVA獲取優(yōu)酷、土豆、酷6、6間房等視頻,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-10-10
  • Hadoop 中 HBase Shell命令的詳解

    Hadoop 中 HBase Shell命令的詳解

    這篇文章主要介紹了Hadoop 中 HBase Shell命令的詳解的相關(guān)資料,需要的朋友可以參考下
    2017-10-10
  • Java中Switch的使用方法及新特性

    Java中Switch的使用方法及新特性

    在java中控制流程語(yǔ)句是由選擇語(yǔ)句、循環(huán)語(yǔ)句、跳轉(zhuǎn)語(yǔ)句構(gòu)成,選擇語(yǔ)句包括if和switch,在過(guò)多的使用if語(yǔ)句嵌套會(huì)使程序很難閱讀,這時(shí)就可以用到switch語(yǔ)句,這篇文章主要給大家介紹了關(guān)于Java中Switch的使用方法及新特性的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • java中的阻塞隊(duì)列應(yīng)用場(chǎng)景及代碼實(shí)例

    java中的阻塞隊(duì)列應(yīng)用場(chǎng)景及代碼實(shí)例

    這篇文章主要介紹了java中的阻塞隊(duì)列應(yīng)用場(chǎng)景及代碼實(shí)例阻塞隊(duì)列是一種特殊的隊(duì)列,它提供了線程安全的操作,并在隊(duì)列為空或滿時(shí)提供了阻塞的功能,阻塞隊(duì)列通常用于多線程場(chǎng)景,其中生產(chǎn)者線程向隊(duì)列中添加元素,而消費(fèi)者線程從隊(duì)列中獲取元素,需要的朋友可以參考下
    2024-01-01
  • Java異常的處理機(jī)制

    Java異常的處理機(jī)制

    這篇文章主要介紹了Java異常的處理機(jī)制,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • spring定義和裝配bean詳解

    spring定義和裝配bean詳解

    這篇文章主要介紹了spring定義和裝配bean詳解,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • Java使用MessageFormat應(yīng)注意的問(wèn)題

    Java使用MessageFormat應(yīng)注意的問(wèn)題

    這篇文章主要介紹了Java使用MessageFormat應(yīng)注意的問(wèn)題,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-06-06

最新評(píng)論