Maven packaging dependencies and code separation

premise

When uploading the code to the server, the dependencies are often repeatedly uploaded (in many cases, the dependencies are unchanged), wasting a lot of time.

After the dependency and code are separated, we can only upload the code jar package (small and fast) without changing the dependency.

accomplish

Just add the following build.

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.0.RELEASE</version>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>non-exists</groupId>
                            <artifactId>non-exists</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/libs</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 After maven install, use the libs directory and jar package in the target directory . We only need to upload the libs directory and jar package to the server. After modifying the code, you only need to upload the jar package when the dependencies remain unchanged.

running on the server

java -Dloader.path=./libs -jar *.jar

Guess you like

Origin blog.csdn.net/wai_58934/article/details/126530637