Specific functions of pom.xml tags in Maven project

          The core of maven is pom.xml. maven is used to better help project management package dependency. If you want to introduce a jar package, you need to add < dependency > < / dependency > to the POM file to rely on the corresponding jar package.

1. < parent > < / parent > label

    (1)   If there are two web projects W1 and W2, one java project, which depends on the same jar package, jsp-api-2.2.jar. If the dependency of jsp-api-2.2.jar is introduced into the respective pom files, when the version of jsp-api-2.2.jar changes, the pom files of the three projects will have to be changed. The more dependencies in the project, the more modifications. At this point, you can use the parent tag to create a parent project. The packaging type is pom. There is no code in the parent project, but only manages the public dependencies between multiple projects. Define the dependency on jsp-api-2.2.jar in the pom file of the parent project. In the three subprojects of W1W2J1, you only need to define < parent > < / parent >, and write the pom coordinates of the parent project in the parent tag to reference jsp-api-2.2.jar.

    (2) There is a jsp-api-2.2.jar. Only W1W2 web projects need it. J1 project is a java project and does not need it. So how do you rely on it. If the dependencies on jsp-api-2.2.jar are defined in W1W2, it is inconvenient to modify when the version of jsp-api-2.2.jar changes. The solution is to use < dependencymanagement > < / dependencymanagement > in the pom file of the parent project to manage jsp-api-2.2.jar. If any sub project needs to be used, the sub project will use it in its own pom file

Parent pom.xml file

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo</groupId>
    <artifactId>demo-platform-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>

    <name>demo-platform-parent</name>
    <url>http://demo.com</url>

    <properties>
        <junit.version>4.12</junit.version>

        <spring.version>4.3.8.RELEASE</spring.version>
    </properties>


    <dependencyManagement>

        <!-- TEST begin -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

        </project>

        ​

Subproject

<dependencies><dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
 
 </dependency></dependencies>
 

2.<modules></modules>

      < modules > in pom.xml means modules, which are used to manage sub modules,

For example:

<modules>
        <module>springmvc-01-servlet</module>
        <module>springmvc_02_hellomvc</module>
        <module>springmvc-03-annotation</module>
        <module>springmvc_04_controller</module>
        <module>springmvc_05_json</module>
        <module>springmvc_05_json</module>
        <module>springmvc_06_ajax</module>
        <module>springmvc_07_intercepter</module>
        <module>springmvc_08_file</module>
        <module>springmvc-01-servlet</module>
    </modules>

The project has six sub modules

3.<properties></properties>

          Through the properties element, users can customize one or more Maven attributes, and then reference the attribute in the form of * * ${attribute name} * * elsewhere in POM.
The greatest significance of this approach lies in the elimination of duplication and unified management.

For example:

​
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.scut</groupId>
  <artifactId>company</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>mychart Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>  
        <!-- spring Version number -->  
        <spring.version>4.0.2.RELEASE</spring.version>  
        <!-- mybatis Version number -->  
        <mybatis.version>3.2.6</mybatis.version>  
        <!-- log4j Log file management pack version -->  
        <slf4j.version>1.7.7</slf4j.version>  
        <log4j.version>1.2.17</log4j.version>  
    </properties>  
  
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    	<groupId>javax</groupId>
    	<artifactId>javaee-api</artifactId>
    	<version>7.0</version>
    </dependency>
    
    <!-- spring Core package -->  
    <dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-oxm</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context-support</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-test</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<!-- mybatis Core package -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis</artifactId>
		<version>${mybatis.version}</version>
	</dependency>
	<!-- mybatis/spring package -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis-spring</artifactId>
		<version>1.2.2</version>
	</dependency>
	<!-- Import java ee jar package -->
	<dependency>
		<groupId>javax</groupId>
		<artifactId>javaee-api</artifactId>
		<version>7.0</version>
	</dependency>
	<!-- Import Mysql Database link jar package -->
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.30</version>
	</dependency>
	<!-- Import dbcp of jar Bag, used in applicationContext.xml Configuration database in -->
	<dependency>
		<groupId>commons-dbcp</groupId>
		<artifactId>commons-dbcp</artifactId>
		<version>1.2.2</version>
	</dependency>
	<!-- JSTL Label class -->
	<dependency>
		<groupId>jstl</groupId>
		<artifactId>jstl</artifactId>
		<version>1.2</version>
	</dependency>
	<!-- Log file management pack -->
	<!-- log start -->
	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>${log4j.version}</version>
	</dependency>


	<!-- Format the object to facilitate the output of logs -->
	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>fastjson</artifactId>
		<version>1.1.41</version>
	</dependency>


	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>${slf4j.version}</version>
	</dependency>

	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<!-- log end -->
	<!-- Reflect JSON -->
	<dependency>
		<groupId>org.codehaus.jackson</groupId>
		<artifactId>jackson-mapper-asl</artifactId>
		<version>1.9.13</version>
	</dependency>
	<!-- Upload component package -->
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.3.1</version>
	</dependency>
	<dependency>
		<groupId>commons-io</groupId>
		<artifactId>commons-io</artifactId>
		<version>2.4</version>
	</dependency>
	<dependency>
		<groupId>commons-codec</groupId>
		<artifactId>commons-codec</artifactId>
		<version>1.9</version>
	</dependency>
	<dependency>
		<groupId>org.apache.hive</groupId>
		<artifactId>hive-service</artifactId>
		<version>0.13.1</version>
	</dependency>
	<dependency>
		<groupId>org.apache.thrift</groupId>
		<artifactId>libthrift</artifactId>
		<version>0.9.0</version>
	</dependency> 
	<dependency>
		<groupId>impala</groupId>
		<artifactId>impala</artifactId>
		<version>0.41</version>
		<scope>system</scope>
		<systemPath>${basedir}/libs/ImpalaJDBC41.jar</systemPath>
	</dependency>
	  <dependency>
		  <groupId>kylin</groupId>
		  <artifactId>kylin</artifactId>
		  <version>1.6.0</version>
		  <scope>system</scope>
		  <systemPath>${basedir}/libs/kylin-jdbc-1.6.0-SNAPSHOT.jar</systemPath>
	  </dependency>
	  <!--Echart Class package-->
	  <dependency>
		  <groupId>com.github.abel533</groupId>
		  <artifactId>ECharts</artifactId>
		  <version>2.2.7</version>
	  </dependency>
	  <!-- gson library -->
		<dependency>
		    <groupId>com.google.code.gson</groupId>
		    <artifactId>gson</artifactId>
		    <version>2.2.4</version>
		</dependency>
	  
	<dependency>
	    <groupId>org.springframework.data</groupId>
	    <artifactId>spring-data-redis</artifactId>
	    <version>1.0.1.RELEASE</version>
	</dependency>
	
	<!-- https://mvnrepository.com/artifact/org.jvnet.hudson/trilead-ssh2 remote call -- >
	<dependency>
	    <groupId>org.jvnet.hudson</groupId>
	    <artifactId>trilead-ssh2</artifactId>
	    <version>build212-hudson-6</version>
	</dependency>

	  <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
	  <dependency>
		  <groupId>org.apache.maven.plugins</groupId>
		  <artifactId>maven-compiler-plugin</artifactId>
		  <version>3.8.0</version>
	  </dependency>
<!--woc How did it pass-->


  </dependencies>
  <build>
    <finalName>mychart</finalName>
    <plugins>
    	<plugin>
        	<groupId>org.apache.maven.plugins</groupId>

          	<artifactId>maven-compiler-plugin</artifactId>
         	<configuration>
            	<source>1.7</source>
            	<target>1.7</target>
          	</configuration>
       	</plugin>



<!--      	<plugin>-->
<!--        	<groupId>org.mortbay.jetty</groupId>-->
<!--        	<artifactId>maven-jetty-plugin</artifactId>-->
<!--      	</plugin>        -->
		<plugin>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-maven-plugin</artifactId>
			<version>9.3.14.v20161028</version>
			<configuration>
				<webAppConfig>
					<maxFormContentSize>600000</maxFormContentSize>
					<contextPath>/file</contextPath>
				</webAppConfig>


				<scanIntervalSeconds>3</scanIntervalSeconds>
				<webAppSourceDirectory>${basedir}/webapp/</webAppSourceDirectory>
				<stopPort>9998</stopPort>
				<stopKey>stop</stopKey>
				<jettyConfig/>
				<systemProperties>
					<systemProperty>
						<name>UrlEncoded</name>
						<value>GBK</value>
					</systemProperty>
				</systemProperties>
			</configuration>
		</plugin>
    </plugins>
  </build>
</project>

​

Define the version number of spring through < Properties > and call the version number of spring through ${spring.version}.

${project.basedir}: indicates the root directory of the current project, that is, the location of the current pom.xml file. It can also be written in a simplified way: ${basedir}
${project.version}: indicates the version of the current project, which can be abbreviated as ${version}
${project.build.sourceDirectory}: indicates the main source directory of the project. The default is src/main/java/
${project.build.testSourceDirectory}: the test source directory of the project. The default is / src/test/java/
${project.build.directory}: indicates the build directory of the project. The default value is ${basedir}/target
${project.build.outputDirectory}: indicates the main code compilation output directory of the project. The default is ${basedir}/target/classes
${project.build.testOutputDirectory}: indicates the project test code compilation output directory. The default is ${basedir} / target / test classes
${project.build.sourceDirectory}: indicates the src/main/java folder by default.

Tags: Java Maven jar

Posted on Sat, 27 Nov 2021 21:46:45 -0500 by Yaak