IDEA中maven项目打包生成可执行jar

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

其中build节点配置如下

<build>
    <plugins>
      <plugin>
        <groupId>org.scala-toolsgroupId>
        <artifactId>maven-scala-pluginartifactId>
        <version>2.15.2version>
        <executions>
          <execution>
            <goals>
              <goal>compilegoal>
              <goal>testCompilegoal>
            goals>
          execution>
        executions>
      plugin>

      <plugin>
        <artifactId>maven-compiler-pluginartifactId>
        <version>3.6.0version>
        <configuration>
          <source>1.8source>
          <target>1.8target>
        configuration>
      plugin>
      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-assembly-pluginartifactId>
        <version>2.3version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependenciesdescriptorRef>
          descriptorRefs>
        configuration>
      plugin>

      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-surefire-pluginartifactId>
        <version>2.19version>
        <configuration>
          <skip>trueskip>
        configuration>
      plugin>

      <plugin>
        <groupId>org.codehaus.mojogroupId>
        <artifactId>build-helper-maven-pluginartifactId>
        <version>1.8version>
        <executions>
          <execution>
            <id>add-resourceid>
            <phase>generate-resourcesphase>
            <goals>
              <goal>add-resourcegoal>
            goals>
            <configuration>
              <resources>
                <resource>
                  <directory>src/main/javadirectory>
                  <includes>
                    <include>com/netmarch/*.txtinclude>
                  includes>
                resource>
              resources>
            configuration>
          execution>
        executions>
      plugin>

      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-shade-pluginartifactId>
        <version>2.4.3version>
        <executions>
          <execution>
            <phase>packagephase>
            <goals>
              <goal>shadegoal>
            goals>
            <configuration>
              <filters>
                <filter>
                  <artifact>*:*artifact>
                  <excludes>
                    <exclude>META-INF/*.SFexclude>
                    <exclude>META-INF/*.DSAexclude>
                    <exclude>META-INF/*.RSAexclude>
                  excludes>
                filter>
              filters>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.xxx.AppmainClass>
                transformer>
              transformers>
            configuration>
          execution>
        executions>
      plugin>
    plugins>
    <defaultGoal>packagedefaultGoal>
  build>

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

 参考来源:

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

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

你可能感兴趣的