溫馨提示×

maven怎么打包第三方jar包

小億
493
2024-02-27 10:38:03
欄目: 編程語言

要打包第三方jar包,可以通過以下幾種方式:

  1. 將第三方jar包手動放入項目的lib目錄中,然后在pom.xml文件中使用system指定該jar包的路徑,這樣在打包時會將該jar包一起打包到最終的輸出文件中。
<dependency>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/example.jar</systemPath>
</dependency>
  1. 使用Maven插件將第三方jar包安裝到本地倉庫中,然后在pom.xml文件中正常引入該依賴即可。
mvn install:install-file -Dfile=path/to/example.jar -DgroupId=com.example -DartifactId=example -Dversion=1.0 -Dpackaging=jar
<dependency>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
</dependency>
  1. 使用Maven的assembly插件將項目及第三方jar包一起打包成一個可執行的jar包。

在pom.xml文件中配置assembly插件:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.example.MainClass</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

執行mvn clean package命令即可打包生成含有第三方jar包的可執行jar文件。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女