The content of this article is about how to use maven to package and publish springboot. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
This article shares how to use maven to facilitate us to create springboot release packages; I use the idea development tool here, and first create a project structure of multiple modules, as shown in the figure:
To package projects of multiple modules, the packaged plug-ins are generally configured in the parent pom. The pom of other modules does not require special configuration. When the configuration is completed, click The package of the maven tool in idea can perform a series of packaging operations;
Here first use the maven-jar-plugin plug-in and add the following configuration in the parent pom:
<!--通过maven-jar-plugin插件打jar包--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <!--main入口--> <mainClass>com.platform.WebApplication</mainClass> </manifest> </archive> <!--包含的配置文件--> <includes> </includes> <excludes> </excludes> </configuration> </plugin>
We need to pay attention to the following nodes in the above configuration:
mainClass: We need to specify the main entrance, of course This is not necessary. If there are multiple main entries in the same project, it is only needed when packaging. Only one main entry is actually ignored;
classpathPrefix: Specify to add to the classpath The prefix folder name where the dependent package is located
addClasspath: the dependent package is added to the classpath, the default is true
includes: needs to be included in the jar The files in are generally not configured (note: if the configuration path is inappropriate, the class may be excluded)
excludes: If you are making an external configuration file for the jar package, you need to do this here Use excludes to exclude these configuration files and package them in the jar together.
Use the maven-jar-plugin plug-in to package the project. At this time, you can package it through the maven package command and you can see the jar. There is a lib folder (default), which contains third-party dependency packages introduced in the project. Through java -jar xxx.jar, you can see that the jar is successfully started:
In standard projects, there are generally dev, test, uat, pro and other environments. Different configurations are required for these environments. In springboot, different configurations can be distinguished by application-dev|test|...yml. Just add spring.profiles.active=dev|test... to the default application.yml;
This method has inconveniences, such as local debugging or publishing and online need to be modified back and forth. The active value (of course, when starting through jar, you can also set the command line active parameter) is not very convenient; below, configure profiles in the pom, and then select the configuration used for startup by clicking on the idea interface; first, in the main layer Create the configuration file directory with the following structure:
In order to distinguish the tests, server.port is set for different environment configuration files to specify different ports (dev: 3082, pro: 3182)
Then, configure the following profiles information in the parent pom:
<profiles> <profile> <id>dev</id> <!--默认运行配置--> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <activeProfile>dev</activeProfile> </properties> </profile> <profile> <id>test</id> <properties> <activeProfile>test</activeProfile> </properties> </profile> <profile> <id>uat</id> <properties> <activeProfile>uat</activeProfile> </properties> </profile> <profile> <id>pro</id> <properties> <activeProfile>pro</activeProfile> </properties> </profile> </profiles>
Node description:
activeByDefault :Set as the default running configuration
activeProfile: The selected startup configuration, its value corresponds to the dev|test|pro folder under the profiles created above
Then, add the resources node configuration to the build in the pom:
<resources> <!--指定所使用的配置文件目录--> <resource> <directory>src/main/profiles/${activeProfile}</directory> </resource> </resources>
At this moment our configuration is complete. Under normal circumstances, the maven module on the idea can see such a picture. Surface:
At this time, we only need to check these buttons. Whether it is debugging or final packaging, follow this to obtain the required configuration files.
The above is the detailed content of How to use maven to package and release springboot. For more information, please follow other related articles on the PHP Chinese website!

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunondifferentoperatingsystemswithoutmodification.TheJVMcompilesJavacodeintoplatform-independentbytecode,whichittheninterpretsandexecutesonthespecificOS,abstractingawayOS

Javaispowerfulduetoitsplatformindependence,object-orientednature,richstandardlibrary,performancecapabilities,andstrongsecurityfeatures.1)PlatformindependenceallowsapplicationstorunonanydevicesupportingJava.2)Object-orientedprogrammingpromotesmodulara

The top Java functions include: 1) object-oriented programming, supporting polymorphism, improving code flexibility and maintainability; 2) exception handling mechanism, improving code robustness through try-catch-finally blocks; 3) garbage collection, simplifying memory management; 4) generics, enhancing type safety; 5) ambda expressions and functional programming to make the code more concise and expressive; 6) rich standard libraries, providing optimized data structures and algorithms.

JavaisnotentirelyplatformindependentduetoJVMvariationsandnativecodeintegration,butitlargelyupholdsitsWORApromise.1)JavacompilestobytecoderunbytheJVM,allowingcross-platformexecution.2)However,eachplatformrequiresaspecificJVM,anddifferencesinJVMimpleme

TheJavaVirtualMachine(JVM)isanabstractcomputingmachinecrucialforJavaexecutionasitrunsJavabytecode,enablingthe"writeonce,runanywhere"capability.TheJVM'skeycomponentsinclude:1)ClassLoader,whichloads,links,andinitializesclasses;2)RuntimeDataAr

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

The five major features of Java are polymorphism, Lambda expressions, StreamsAPI, generics and exception handling. 1. Polymorphism allows objects of different classes to be used as objects of common base classes. 2. Lambda expressions make the code more concise, especially suitable for handling collections and streams. 3.StreamsAPI efficiently processes large data sets and supports declarative operations. 4. Generics provide type safety and reusability, and type errors are caught during compilation. 5. Exception handling helps handle errors elegantly and write reliable software.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
