Chapter 5 Maven Common Settings

5.1 Maven property settings

  <properties>
    <!-- maven构建项目使用的编码,避免中文乱码 -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- 编译代码使用的jdk版本 -->
    <maven.compiler.source>1.8</maven.compiler.source>
    <!-- 运行程序使用的jdk版本 -->
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

5.2 Maven's global variables

  • In the pom.xml file of Maven, <properties> is used to define global variables, and the value of the variable is referenced in the form of ${property_name} in the POM.
  • Custom global variables generally define the version number of dependencies. When you use multiple versions of the same version in your project, use the global variable definition first, and then use the ${variable name} to
    define the global variable:
<properties>
	<spring.version>5.2.5.RELEASE</spring.version>
</properties>

Insert picture description here

5.3 Specify resource location

  • All *.java files in the two directories src/main/java and src/test/java will be compiled in the compile and test comiple phases respectively, and the compilation results will be placed in the target/classes and target/test classes directories, but Other files in these two directories will be ignored. If you need to put the file package in the src directory into the target/classes directory as part of the output jar. Need to specify the location of the resource file. The following content is placed in the <buid> tag.
<build>
	<resources>
		<resource>
			<directory>src/main/java</directory><!-- 所在的目录 ---->
			<include><!-- 包括目录下的 .properties,.xml 文件都会扫描到 ---->
				<include>**/*.properties</include>
				<include>**/*.xml</include>
			</includes>
			<!-- filtering选项 false不启用过滤器, *.property已经起到过滤的作用了 -->
			<filtering>false</filtering>
		</resource>
	</resources>
</build>
  • Role: will be used in mybatis
  1. When maven executes the compiled code, it will copy the files in the src/main/resources directory to the target/classes directory. The non-java files in the src/main/java directory will not be processed and will not be copied to the target/classes directory.
  2. Our program needs to put some files in the src/main/java directory. When we execute the java program, we need to use the files in the src/main/java directory. We need to tell maven to compile src/main/ in mvn compile. For programs in the java directory, you need to copy the files to the target/classes directory together. At this time, you need to add <resources> to <build>

Guess you like

Origin blog.csdn.net/Lu1048728731/article/details/114819124