This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11769|Reply: 0

[Source] Maven projects package projects and dependencies separately

[Copy link]
Posted on 2022-3-11 17:19:28 | | | |
Requirements: Use maven to manage a new Spring Boot project, when the development is completed, the project and dependencies are packaged into a jar file, the file size is more than 160M, every time an update is released (even if only one line of code is changed), you need to upload the file of more than 100 MB to the server, which takes 5 minutes to upload, which is a great waste of bandwidth and time.

Analysis: The reason for the large jar file is mainly dependenciesA lot of third-party dependencies are introducedIn fact, there is not much code written by the project itself. How to package your new projects and third-party dependencies separately? Output third-party dependencies to a separate folder, after all, third-party dependencies are generally not updated.

The default package pom.xml file configuration is as follows:

usemvn clean packageAfter the command packages the jar file:



Modify the pom.xml file with the following configuration:

Note!!!includes must add the module of your project completely, that is, package your newly created module into a jar file.

Repackage with the mvn clean package command, as shown in the following image:



After packaging your own project, itsvse-0.0.1-SNAPSHOT.jar file returnsLess than 1M, package all third-party dependencies into a lib folder, and only need to update itsvse-0.0.1-SNAPSHOT.jar when updating (without considering the introduction of new third-party dependencies).

The project start command is as follows:


Reference articles:

Spring Boot Maven Plugin Documentation:https://docs.spring.io/spring-bo ... ference/htmlsingle/
Apache Maven Dependency Plugin:https://maven.apache.org/plugins ... n/sources-mojo.html
https://blog.csdn.net/weixin_35971547/article/details/90521411
https://www.jianshu.com/p/138f98f684d3





Previous:Linux ssh: command not found
Next:Elasticsearch automatically cleans up indexes to free up disk space
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com