☆☆☆★☆☆☆

唯有努力才能活成自己想要活成的样子

导航

maven的pom.xml打包配置

 <build>
    <plugins>
    <!-- 指定maven编译的jdk版本,如果不指定,maven3默认用jdk 1.5 maven2默认用jdk1.3 -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
    <!-- 一般而言,target与source是保持一致的,但是,有时候为了让程序能在其他版本的jdk中运行
    (对于低版本目标jdk,源代码中不能使用低版本jdk中不支持的语法),会存在target不同于source的情况 -->
    <source>1.8</source> <!-- 源代码使用的JDK版本 -->
    <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
    <encoding>UTF-8</encoding><!-- 字符集编码 -->
    <verbose>true</verbose>
    <!--<showWarnings>true</showWarnings>-->
    <!-- 要使compilerVersion标签生效,还需要将fork设为true,用于明确表示编译版本配置的可用 -->
    <!--<fork>true</fork>-->
    <!-- 使用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> -->
    <!-- <executable>path-to-javac </executable>-->
    <!-- 指定插件将使用的编译器的版本 -->
    <!--<compilerVersion>1.3</compilerVersion>-->
    <!-- 编译器使用的初始内存 -->
    <!--<meminitial>128m</meminitial>-->
    <!-- 编译器使用的最大内存 -->
    <!--<maxmem>512m</maxmem>-->
    <!-- 这个选项用来传递编译器自身不包含但是却支持的参数选项 -->
    <!--<compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>-->
    </configuration>
    </plugin>

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId> maven-assembly-plugin </artifactId>
    <configuration>
    <!-- 使用Maven预配置的描述符-->
    <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    </configuration>
    <executions>
    <execution>
    <id>make-assembly</id>
    <!-- 绑定到package生命周期 -->
    <phase>package</phase>
    <goals>
    <!-- 只运行一次 -->
    <goal>single</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>

 实例:

<build>
        <finalName>utils</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <!-- 对要打的jar包进行配置 -->
                <configuration>
                    <archive>
                        <!--生成的jar中,不要包含pom.xml和pom.properties这两个文件-->
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifest>
                            <!--是否要把第三方jar放到manifest的classpath中-->
                            <addClasspath>true</addClasspath>
                            <!-- 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                    <!--过滤掉不希望包含在jar中的文件-->
                    <excludes>
                        <!-- 排除不需要的文件夹(路径是jar包内部的路径) -->
                        <exclude>**/assembly/</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <!--<version>2.3.2</version>-->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!--解决guava冲突使用下面plugin-->
            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-shade-plugin</artifactId>-->
            <!--<version>3.0.0</version>-->
            <!--<executions>-->
            <!--<execution>-->
            <!--<phase>package</phase>-->
            <!--<goals>-->
            <!--<goal>shade</goal>-->
            <!--</goals>-->
            <!--<configuration>-->
            <!--<relocations>-->
            <!--<relocation>-->
            <!--<pattern>com.google.common</pattern>-->
            <!--<shadedPattern>shaded.com.google.common</shadedPattern>-->
            <!--</relocation>-->
            <!--</relocations>-->
            <!--<artifactSet>-->
            <!--<includes>-->
            <!--<include>*:*</include>-->
            <!--</includes>-->
            <!--</artifactSet>-->
            <!--</configuration>-->
            <!--</execution>-->
            <!--</executions>-->
            <!--</plugin>-->

            <!--以下选一个-->
            <plugin>
                <artifactId> maven-assembly-plugin </artifactId>
                <configuration>
                    <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>

            <!--<plugin>-->
            <!--<groupId>org.apache.maven.plugins</groupId>-->
            <!--<artifactId>maven-assembly-plugin</artifactId>-->
            <!--<version>2.4</version>-->
            <!--&lt;!&ndash; 对项目的组装进行配置 &ndash;&gt;-->
            <!--<configuration>-->
            <!--&lt;!&ndash; 指定assembly插件的配置文件所在位置 &ndash;&gt;-->
            <!--<descriptors>-->
            <!--<descriptor>src/main/resources/assembly/package.xml</descriptor>-->
            <!--</descriptors>-->
            <!--</configuration>-->
            <!--<executions>-->
            <!--<execution>-->
            <!--<id>make-assembly</id>-->
            <!--&lt;!&ndash; 将组装绑定到maven生命周期的哪一阶段 &ndash;&gt;-->
            <!--<goals>-->
            <!--&lt;!&ndash; 指定assembly插件的打包方式&ndash;&gt;-->
            <!--<goal>single</goal>-->
            <!--</goals>-->
            <!--</execution>-->
            <!--</executions>-->
            <!--</plugin>-->

        </plugins>
    </build>

 

posted on 2020-04-20 16:40  Yr-Zhang  阅读(1463)  评论(0编辑  收藏  举报