SpringBoot + at the same time into the jar package to the local lib directory Maven playing at war package

1 Introduction

        SpringBoot Maven and the emergence of our development provides a great convenience, as the saying everything has two sides, there is a simple place where there will be trouble, here to record a project using Maven package SpringBoot when a local reference appears issue a third-party jar package.

2. Description of the problem

        SpringBoot a project, usually when referring to third-party jar package, specified in the pom file dependencies and the jar package on it, this is a very normal operations maven, configured dependence, maven automatically insert the appropriate jar package join the project, the development time can be introduced directly into the classes and methods in the jar package, when the package maven will also depend on the jar package into the next WEB-INF / lib, happy, how happy -
        but there are always a project, due to some reason the column must be provided to introduce others to your jar packages that do not exist on a public warehouse, if there are better PW, PW began no headache.
        Some people say, create a new directory in the local maven repository, a custom path to jar package into them, and then add in the pom.xml in the corresponding <dependency> configuration would be all right! This is indeed possible, but this approach is not conducive to project development and engineering team retained the source code, and do not effect the code downloaded from the project will be able to run directly compiled, so taking into account the integrity of the code, the program pass out a.
        After a review of some relevant information, we found that the use <dependency> in <systemPath> can achieve the effect of third-party references jar package, and then set the spring-boot-maven-plugin in includeSystemScope it is true, like this:

<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>

    <groupId>com.st.springboot</groupId>
    <artifactId>ingredients-java</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    
    <name>ingredients-java</name>
    
	<dependencies>
		<dependency>
	        <groupId>org.bouncycastle</groupId>
	        <artifactId>bcprov-jdk16</artifactId>
	        <version>1.46</version>
	        <scope>system</scope>
	        <systemPath>${project.basedir}/src/main/resources/jar/bcprov-jdk16-1.46.jar</systemPath>
	    </dependency>
    </dependencies>
	<build>
		<plugins>
			<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Set finished very happy, if that idea, and even see the contents of the bag can be displayed even IDE:
Here Insert Picture Description
I thought the satisfaction of all, however, there is a problem in the program developed, packaged deployment, I found local references jar package are they not hit the lib into the WEB-INF directory, jar package still in the original location of the project stood up!

3. solve the problem

        Time is running out, first of all lib directory jar package referenced to go into the war package, do actually works, the war package deployed successfully go up. But this has not ah, the fundamental problem is not resolved, if one day intends to set up a regular automatic packaging maven deploy what not to cool a ......
        continued access to information to find a solution, and finally work pays off, providing a plug-in specifically address maven fight the war package when referring to question local package, and this thing called maven-war-plugin!
So I became the pom.xml following like this:

<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>

    <groupId>com.st.springboot</groupId>
    <artifactId>ingredients-java</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    
    <name>ingredients-java</name>
    
	<dependencies>
		<dependency>
	        <groupId>org.bouncycastle</groupId>
	        <artifactId>bcprov-jdk16</artifactId>
	        <version>1.46</version>
	        <scope>system</scope>
	        <systemPath>${project.basedir}/src/main/resources/jar/bcprov-jdk16-1.46.jar</systemPath>
	    </dependency>
    </dependencies>
	<build>
		<plugins>
			<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <!-- 下面是为了将本地jar包打入WEB-INF/lib下而增加的配置-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <webResources>
                        <resource>
                        	<!-- 指向的是包含你所有要用jar包的目录 -->
                            <directory>${project.basedir}/src/main/resources/jar</directory> 
                            <!-- 编译后要把这些jar包复制到的位置 -->
                            <targetPath>WEB-INF/lib</targetPath>  
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

After configuration, run the package command again, to discover local jar package perfect scored under WEB-INF / lib, this problem has been solved!

Elsewhere there is a need to pay attention, due to the use of a maven-war-plugin, jar packaging therefore does not apply when oh ~

Released two original articles · won praise 0 · Views 65

Guess you like

Origin blog.csdn.net/ZuoRuoNuanYang/article/details/104300612