The correct way of configuration file (2)

The correct way of configuration file (2)

background

From " Spring boot hits jar package to separate lib, and the configuration file is in the correct way >In, you can separate the configuration file from the jar package that depends on the third party, but it's a little bloated. Today, I will provide a way for you to refer to.

Deployment environment

  • window 10
  • redhat 6.4
  • Other versions didn't try, it should be ok

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.elvish</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>test2</name>
	<description>test project for Spring Boot</description>

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

	<build>
		<finalName>test</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>target/lib</outputDirectory>
							<excludeTransitive>false</excludeTransitive>
							<stripVersion>false</stripVersion>
							<includeScope>runtime</includeScope>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<layout>ZIP</layout>
					<includes>
						<include>
							<groupId>cn.jstars</groupId>
							<artifactId>datatocloud</artifactId>
						</include>
					</includes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<filtering>true</filtering>
				<directory>src/main/resources</directory>
				<excludes>
					<exclude>static/**</exclude>
					<exclude>templates/**</exclude>
					<exclude>*.yml</exclude>
					<exclude>*.properties</exclude>
					<exclude>*.xml</exclude>
					<exclude>*.txt</exclude>
				</excludes>
			</resource>
		</resources>
	</build>

</project>


interpretative statement

  • Maven dependency plugin prints the third-party package that the project depends on and puts it under lib
  • Spring boot Maven plugin spring boot package plug-in, only the jar package of the project running is reserved
  • resources excludes files that we need to be external

Operation mode

Deploy the lib package and test.jar (running package) under target and the files you need to be external under src/main/resources to the same directory of the server, such as

  • lib
  • test.jar
  • *.yml
  • *.xml
  • *.properties
  • static
  • templates

Final operation

java -jar -Dloader.path="lib/" test.jar

Perfect operation, think it's good, like it, collect it

Tags: Maven Spring Apache xml

Posted on Mon, 06 Jan 2020 14:32:57 -0800 by tdeez173