美文网首页
实现maven打包 可执行jar与依赖jar分离

实现maven打包 可执行jar与依赖jar分离

作者: 舒尔诚 | 来源:发表于2019-03-08 14:18 被阅读0次

    <build>
    <resources>
    <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <includes>
    <include>/.xml</include>
    <include>
    /.properties</include>
    <include>/.yml</include>
    </includes>
    </resource>

    <resource>
    <targetPath>${project.build.directory}/classes</targetPath>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <includes>

    <include>
    /.xml</include>
    <include>/.properties</include>
    <include>
    /.yml</include>
    </includes>
    </resource>
    </resources>

        <plugins>
            <!-- 资源文件拷贝插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>${project.artifactId}-${project.version}</warName>
                </configuration>
            </plugin>
            <!-- 跳过测试代码 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <!-- maven打包成jar的插件 -->
            <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <!-- 把target/classes/下的文件导入到jar内 -->
                    <classesDirectory>target/classes/</classesDirectory>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <archive>
                        <manifest>
                            <!-- 指定程序入口 -->
                            <mainClass>${spring-cloud-main-class}</mainClass>
                            <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                            <useUniqueVersions>false</useUniqueVersions>
                            <addClasspath>true</addClasspath>
                            <!-- 服务依赖的jar包放在lib目录下 -->
                            <classpathPrefix>lib/</classpathPrefix>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </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>
                            <!-- <includeScope>compile</includeScope> -->
                            <type>jar</type>
                            <includeTypes>jar</includeTypes>
                            <!-- 存放服务依赖的jar包,存放在服务相同目录的lib文件夹下 -->
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    相关文章

      网友评论

          本文标题:实现maven打包 可执行jar与依赖jar分离

          本文链接:https://www.haomeiwen.com/subject/epsrpqtx.html