maven打包时打包指定的lib文件夹

今天在打包自己的spring boot项目时遇到了问题, 报找不到类和符号。

因为我有些依赖是放在项目lib文件夹中,那么打包的时候要连把它一起打包。

 

修改pom.xml, 添加一下内容:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <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>
                    <compilerArguments>
                        <extdirs>lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
        </resources>
    </build>

 

然后cmd切换到项目根路径执行打包命令:mvn clean package -Dmaven.test.skip=true

打包后的jar包结构可以看到lib文件夹被整个打包进去了。

 

 

 

 

posted @ 2019-10-31 22:50  一锤子技术员  阅读(5)  评论(0编辑  收藏  举报  来源