且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用IntelliJ制作具有所有依赖关系的jar文件

更新时间:2022-12-12 20:32:41

您可以使用Maven程序集插件.在pom中添加以下内容:

You can use maven assembly plugin. Add following in your pom :

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.1</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

然后您从命令行执行:

mvn package

或从intellij执行生命周期目标包裹"

or execute lifecycle goal "package" from intellij

请按照以下说明获取更多信息: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

Follow this for more information: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html