Maven编译与打包pom外的jar包

一、外部包目录

二、开发编译时需要引用外部jar包

<plugin>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<source>1.8</source>
		<target>1.8</target>
		<encoding>UTF-8</encoding>
		<compilerArguments>
			<extdirs>${project.basedir}/lib</extdirs>
		</compilerArguments>
	</configuration>
</plugin>

三、打包时需要引用外部jar包

<resources>
	<resource>
		<directory>${project.basedir}/lib</directory>
		<targetPath>BOOT-INF/lib/</targetPath>
		<includes>
			<include>**/*.jar</include>
		</includes>
	</resource>
	<resource>
		<directory>src/main/resources</directory>
		<targetPath>BOOT-INF/classes/</targetPath>
	</resource>
</resources>

四、打包时指定打包名

 <finalName>mztsfrz-api</finalName>

五、完整pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com</groupId>
    <artifactId>mztsfrz-api</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>mztsfrz-api</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <swagger.version>2.8.0</swagger.version>
        <maven-compiler.version>3.1</maven-compiler.version>
        <maven-resources.version>2.6</maven-resources.version>
        <maven-source.version>2.1.2</maven-source.version>
        <maven-war.version>2.4</maven-war.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- swagger config -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
    </dependencies>
    <build>
        <!-- package final name config -->
        <finalName>mztsfrz-api</finalName>
        <!-- package final name config -->
        <!-- influence application.yml config -->
        <!--<resources>-->
            <!--<resource>-->
                <!--<directory>${project.basedir}/lib</directory>-->
                <!--<targetPath>BOOT-INF/lib/</targetPath>-->
                <!--<includes>-->
                    <!--<include>**/*.jar</include>-->
                <!--</includes>-->
            <!--</resource>-->
            <!--<resource>-->
                <!--<directory>src/main/resources</directory>-->
                <!--<targetPath>BOOT-INF/classes/</targetPath>-->
            <!--</resource>-->
        <!--</resources>-->
        <!-- influence application.yml config -->
        <plugins>
            <!-- repackage -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.MztsfrzApiApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>${project.basedir}/lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <!--跳过项目运行测试用例-->
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

注意:开发时需要把打包时需要引用外部jar包(三)注释掉。

发表评论

电子邮件地址不会被公开。 必填项已用*标注