springboot packaged and deployed shared dependency package (distributed development and centralized deployment of microservices)

springboot packaged and deployed shared dependency package (distributed development and centralized deployment of microservices)

####1, the original intention of this article

Normally, after we complete the development of microservices, a single microservice should be deployed on a single virtual machine (docker is also available), and then the service is published to the service registry in a centralized manner. However, for some small projects, this is too complicated and difficult to deploy. , Here is mainly about how to deploy multiple microservices on a single machine by sharing the jar package to solve the above deployment difficulties and how to quickly release and deploy when the bandwidth is insufficient or the network speed is slow.

####2, deployment directory structure

Deployment Directory Answer-

Each microservice and the dependent package (under the lib folder) are in the same level directory. This is the content of Figure 1. Figure 2 shows the file structure, deployment configuration file, and jar package in a single microservice. Here you can see that the jar package of a single microservice is only 32KB, which is very small. ####3 How to package with maven#####You only need to modify the pom file of your springboot project as follows

<build>
		<plugins>
			<plugin>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<useUniqueVersions>false</useUniqueVersions>
							<mainClass>com.rzt.TestApplication</mainClass>
						</manifest>
					</archive>
					<excludes>
						<exclude>*.properties</exclude>
					</excludes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>
								${project.build.directory}/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
 

that's it

This article is automatically published by ArtiPub , a multi- posting platform