maven 瘦包输出配置

2022-06-22  本文已影响0人  后知不觉1

打瘦包lib输出问题

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <!--  生成MANIFEST.MF,将依赖指向lib/        -->
            <classpathPrefix>lib/</classpathPrefix>
           <!--  生成MANIFEST.MF,直接指定主类,不用再java -jar 时指定主类       -->
            <mainClass>org.tianzehao.App</mainClass>
          </manifest>
          <manifestEntries>
            <Class-Path>.</Class-Path>
          </manifestEntries>
        </archive>
      </configuration>
    </plugin>
 <plugin>
    <!--  复制依赖  -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/lib</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

常见问题

1、打包是没有任务执行

image.png
原因

pom.xml配置文件中配置了packaging,值为pom的时候是指该pom文件是父pom不用,无可执行代码。删除即可


image.png

2、配置maven-dependency-plugin不生效

原因

因为pom文件pugins中配置了pluginManagement,pluginManagement一般是用来在父POM中定义,提供给子POM使用,子POM也可以覆盖这个定义


image.png

3、本地依赖打包方式

<build>
  <resources>
    <resource>
      <directory>lib/</directory>
      <includes>
        <include>**/*.jar</include>
      </includes>
    </resource>
  </resources>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>3.3.0</version>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
      <configuration>
        <source>8</source>
        <target>8</target>
      </configuration>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.5.5</version>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.tianzehao.A</mainClass>
            <addClasspath>true</addClasspath>
            <classpathPrefix>./</classpathPrefix>
          </manifest>
          <manifestEntries>
             在MANIFEST.MF文件中classPath 单独添加 该值
            <Class-Path>./hiveTest-1.0-SNAPSHOT.jar</Class-Path>
          </manifestEntries>
        </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>

  </plugins>
</build>
上一篇 下一篇

猜你喜欢

热点阅读