zoukankan      html  css  js  c++  java
  • IDEA中maven项目打包生成可执行jar

    新建maven项目,编写Main方法类,略

    其中build节点配置如下

    <build>
        <plugins>
          <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>testCompile</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
    
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
          </plugin>
    
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
    
          <plugin><!--包含class目录资源文件-->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
              <execution>
                <id>add-resource</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>add-resource</goal>
                </goals>
                <configuration>
                  <resources>
                    <resource>
                      <directory>src/main/java</directory>
                      <includes>
                        <include>com/netmarch/*.txt</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
    
          <plugin><!--将第三方的jar文件打包进来-->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <filters>
                    <filter>
                      <artifact>*:*</artifact>
                      <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                      </excludes>
                    </filter>
                  </filters>
                  <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                      <mainClass>com.xxx.App</mainClass><!--main方法所在类-->
                    </transformer>
                  </transformers>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
        <defaultGoal>package</defaultGoal>
      </build>

    最终 生成带依赖jar和不带依赖jar的两个可执行jar

     参考来源:

    https://my.oschina.net/u/2331760/blog/1913428

    https://blog.csdn.net/u012369535/article/details/90546987

  • 相关阅读:
    整理了所有软件,增加了一些常用的,总计约150个
    Delegate与Action,建议先看为敬
    你们要的练手项目来了
    心塞,我的配置文件到底去哪了
    Modbus,看这个就行了
    PLC做得好好的,我为什么要去学上位机?
    这种取巧的方法,你应该掌握
    从零开始实现放置游戏(十六)——道具系统(1)道具字典
    Elasticsearch 之 Filter 与 Query 有啥不同?
    【小菜学网络】MTU
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12196155.html
Copyright © 2011-2022 走看看