Maven打包将所有的依赖都打入

附上pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.shinho.bi</groupId>
  <artifactId>BaseInterface</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>BaseInterface</name>
   <description>Shinho BI Kylin project for Spring Boot</description>

  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <java.version>1.8</java.version>
      <slf4j.version>1.7.7</slf4j.version>
      <log4j.version>1.2.17</log4j.version>
  </properties>

  <dependencies>
          <dependency>  
           <groupId>junit</groupId>  
           <artifactId>junit</artifactId>  
           <version>4.12</version>  
           <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache</groupId>
            <artifactId>kylin-kap</artifactId>
            <version>2.5.6.1008</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
              <groupId>org.freemarker</groupId>
              <artifactId>freemarker</artifactId>
              <version>2.3.27-incubating</version>
              <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>0.2.9</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jgit</groupId>
            <artifactId>org.eclipse.jgit</artifactId>
            <version>5.0.0.201805301535-rc2</version>
            <scope>compile</scope>
        </dependency>
        <!-- log start -->  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>${log4j.version}</version> 
            <scope>compile</scope> 
        </dependency>  
        <!-- 格式化对象,方便输出日志 --> 
    
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-api</artifactId>  
            <version>${slf4j.version}</version>  
            <scope>compile</scope>
        </dependency>  
    
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-log4j12</artifactId>  
            <version>${slf4j.version}</version>  
            <scope>compile</scope>
        </dependency>  
        <dependency>
          <groupId>org.ehcache</groupId>
          <artifactId>ehcache</artifactId>
          <version>3.4.0</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-io</artifactId>
          <version>2.6</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>  
            <groupId>org.quartz-scheduler</groupId>  
            <artifactId>quartz-jobs</artifactId>  
            <version>2.2.1</version>  
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    
    <repositories>
         <repository>
             <id>shinho-datalake</id>
             <name>shinho-datalake</name>
             <url>http://10.211.62.41:8084/repository/shinho-datalake-gp/</url>
             <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
             </snapshots>
             <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
             </releases>
         </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!--导出所有依赖jar
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>
                            不需要导出的jar
                            <excludeArtifactIds>
                                spring-boot-devtools,junit
                            </excludeArtifactIds>
                            不需要导出的jar
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            导出所有依赖jar-->
             <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <!-- 此处指定main方法入口的class -->
                            <!-- <mainClass>com.xxx.uploadFile</mainClass> -->
                        </manifest>
                    </archive>
               </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
        </plugins>
    </build>
</project>

这里有个误区,注释掉的部分虽然写着是全部打包,但注释的代码实际上是不打依赖包的代码,下面的那部分是全部打包的代码。

猜你喜欢

转载自www.cnblogs.com/wpcnblog/p/9261741.html