[Maven-POM]你真的懂POM文件吗? | 一文带你深入了解POM.XML

⭐作者介绍:大二本科网络工程专业在读,持续学习Java,努力输出优质文章
⭐作者主页:@逐梦苍穹
⭐所属专栏:JavaEE
⭐如果觉得文章写的不错,欢迎点个关注一键三连有写的不好的地方也欢迎指正,一同进步

目录

  • 1、Maven基础回顾
  • 2、POM简介
  • 3、POM详解
    • 3.1、POM单项配置说明
      • 3.1.1、localRepository
      • 3.1.2、interactiveMode
      • 3.1.3、usePluginRegistry
      • 3.1.4、offline
      • 3.1.5、pluginGroups
      • 3.1.6、proxies
      • 3.1.7、servers
      • 3.1.8、mirrors
      • 3.1.9、profiles
      • 3.1.10、Activation
      • 3.1.11、Repositories
      • 3.1.12、activeProfiles
    • 3.2、POM总体配置说明

1、Maven基础回顾

请查看我的这篇文章:[Java Web]Maven:一个管理和构建Java项目的工具

2、POM简介

POM文件(Project Object Model)是Maven项目的核心文件,它描述了Maven项目的基本信息和依赖关系。POM文件是一个XML文件,通常位于项目根目录下的pom.xml文件中。

POM文件包含以下信息:

  1. 项目的基本信息,如项目名称、版本号、描述等。
  2. 项目的依赖关系,包括依赖的外部库、插件等。
  3. 项目的构建配置,包括编译器版本、打包方式、测试配置等。
  4. 项目的开发者信息,包括开发者姓名、邮箱等。

POM文件的作用是:

  1. 管理项目的依赖关系,自动下载和安装依赖的库和插件。
  2. 管理项目的构建过程,自动编译、测试、打包和发布项目。
  3. 管理项目的版本号和发布历史,方便项目的版本控制和管理。
  4. 管理项目的开发者信息,方便项目的协作和交流。

总之,POM文件是Maven项目的核心文件,它提供了项目的基本信息和依赖关系,方便项目的管理和开发。

3、POM详解

3.1、POM单项配置说明

3.1.1、localRepository

 
 <localRepository>usr/local/mavenlocalRepository>

3.1.2、interactiveMode

 
 <interactiveMode>trueinteractiveMode>

3.1.3、usePluginRegistry


 <usePluginRegistry>falseusePluginRegistry>

3.1.4、offline

 
 <offline>falseoffline>

3.1.5、pluginGroups


 <pluginGroups>
  
  <pluginGroup>org.codehaus.mojopluginGroup>
 pluginGroups>

3.1.6、proxies


 <proxies>
  
  <proxy>
   
   <id>myproxyid>
   
   <active>trueactive>
   
   <protocol>httpprotocol>
   
   <host>proxy.somewhere.comhost>
   
   <port>8080port>
   
   <username>proxyuserusername>
   
   <password>somepasswordpassword>
   
   <nonProxyHosts>*.google.com|ibiblio.orgnonProxyHosts>
  proxy>
 proxies>

3.1.7、servers


 <servers>
  
  <server>
   
   <id>server001id>
   
   <username>my_loginusername>
   
   <password>my_passwordpassword>
   
   <privateKey>${usr.home}/.ssh/id_dsaprivateKey>
   
   <passphrase>some_passphrasepassphrase>
   
   <filePermissions>664filePermissions>
   
   <directoryPermissions>775directoryPermissions>
  server>
 servers>

3.1.8、mirrors


 <mirrors>
  
  <mirror>
   
   <id>planetmirror.comid>
   
   <name>PlanetMirror Australianame>
   
   <url>http://downloads.planetmirror.com/pub/maven2url>
   
   <mirrorOf>centralmirrorOf>
  mirror>
 mirrors>

3.1.9、profiles

 
 <profiles>
  
  <profile>
   
   <id>testid>

3.1.10、Activation


   <activation>
    
    <activeByDefault>falseactiveByDefault>
    
    <jdk>1.5jdk>
    
    <os>
     
     <name>Windows XPname>
     
     <family>Windowsfamily>
     
     <arch>x86arch>
     
     <version>5.1.2600version>
    os>
    
    <property>
     
     <name>mavenVersionname>
     
     <value>2.0.3value>
    property>
    
    <file>
     
     <exists>${basedir}/file2.propertiesexists>
     
     <missing>${basedir}/file1.propertiesmissing>
    file>
   activation>

3.1.11、Repositories

  
   <repositories>
    
    <repository>
     
     <id>codehausSnapshotsid>
     
     <name>Codehaus Snapshotsname>
     
     <releases>
      
      <enabled>falseenabled>
      
      <updatePolicy>alwaysupdatePolicy>
      
      <checksumPolicy>warnchecksumPolicy>
     releases>
     
     <snapshots>
      <enabled/><updatePolicy/><checksumPolicy/>
     snapshots>
     
     <url>http://snapshots.maven.codehaus.org/maven2url>
     
     <layout>defaultlayout>
    repository>
   repositories>
   
   <pluginRepositories>
    
          <pluginRepository>           
     <releases>      
      <enabled/><updatePolicy/><checksumPolicy/>
     releases>
     <snapshots>
      <enabled/><updatePolicy/><checksumPolicy/>
     snapshots>
     <id/><name/><url/><layout/>
          pluginRepository>
        pluginRepositories>
  profile>
 profiles>

3.1.12、activeProfiles


   <activeProfiles>
    <activeProfile>env-testactiveProfile>
   activeProfiles>
settings>

3.2、POM总体配置说明

总体配置说明如下:

<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 "> 

     
    <parent> 
         
        <artifactId>xxxartifactId>

        
        <groupId>xxxgroupId> 

         
        <version>xxxversion>

         
        <relativePath>xxxrelativePath> 
    parent> 

     
    <modelVersion> 4.0.0 modelVersion> 

     
    <groupId>xxxgroupId> 

     
    <artifactId>xxxartifactId> 

     
    <packaging> jar packaging> 

     
    <version> 1.0-SNAPSHOT version> 

     
    <name> xxx-maven name> 

     
    <url> http://maven.apache.org url> 

     
    <description> A maven project to study maven. description> 

     
    <prerequisites> 
         
        <maven>maven> 
    prerequisites> 

     
    <issueManagement> 
         
        <system> jira system> 

         
        <url> http://jira.baidu.com/banseon url> 
    issueManagement> 

     
    <ciManagement> 
         
        <system>system> 

         
        <url>url> 

         
        <notifiers> 
             
            <notifier> 
                 
                <type>type> 

                 
                <sendOnError>sendOnError> 

                 
                <sendOnFailure>sendOnFailure> 

                 
                <sendOnSuccess>sendOnSuccess> 

                 
                <sendOnWarning>sendOnWarning> 

                 
                <address>address> 

                 
                <configuration>configuration> 
            notifier> 
        notifiers> 
    ciManagement> 

     
    <inceptionYear /> 

     
    <mailingLists> 
         
        <mailingList> 
             
            <name> Demo name> 

             
            <post> [email protected] post> 

             
            <subscribe> [email protected] subscribe> 

             
            <unsubscribe> [email protected] unsubscribe> 

             
            <archive> http:/hi.baidu.com/banseon/demo/dev/ archive> 
        mailingList> 
    mailingLists> 

     
    <developers> 
         
        <developer> 
             
            <id> HELLO WORLD id>
            
             
            <name> banseon name> 

             
            <email> [email protected] email> 

             
            <url>url> 

             
            <roles> 
                <role> Project Manager role> 
                <role> Architect role> 
            roles> 

             
            <organization> demo organization> 

             
            <organizationUrl> http://hi.baidu.com/xxx organizationUrl> 

             
            <properties> 
                <dept> No dept> 
            properties> 

             
            <timezone> -5 timezone> 
        developer> 
    developers> 

     
    <contributors> 
         
        <contributor> 
             
            <name>name>

            
            <email>email>

            
            <url>url>

            
            <organization>organization>

            
            <organizationUrl>organizationUrl>

             
            <roles> 
                <role> Project Manager role> 
                <role> Architect role> 
            roles>

             
            <timezone>timezone>
            
             
            <properties> 
                <dept> No dept> 
            properties>  
        contributor> 
    contributors> 

     
    <licenses> 
         
        <license> 
             
            <name> Apache 2 name> 

             
            <url> http://www.baidu.com/banseon/LICENSE-2.0.txt url> 

             
            <distribution> repo distribution> 

             
            <comments> A business-friendly OSS license comments> 
        license> 
    licenses> 

     
    <scm> 
         
        <connection> 
            scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)
        connection> 

         
        <developerConnection> 
            scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk 
        developerConnection> 

         
        <tag>tag> 

         
        <url> http://svn.baidu.com/banseon url> 
    scm> 

     
    <organization> 
         
        <name> demo name> 

         
        <url> http://www.baidu.com/banseon url> 
    organization> 

     
    <build> 
         
        <sourceDirectory>sourceDirectory> 

         
        <scriptSourceDirectory>scriptSourceDirectory> 

         
        <testSourceDirectory>testSourceDirectory> 

         
        <outputDirectory>outputDirectory> 

         
        <testOutputDirectory>testOutputDirectory> 

         
        <extensions> 
             
            <extension> 
                 
                <groupId>groupId> 

                 
                <artifactId>artifactId> 

                 
                <version>version> 
            extension> 
        extensions> 

         
        <defaultGoal>defaultGoal> 

         
        <resources> 
             
            <resource> 
                 
                <targetPath>targetPath> 

                 
                <filtering>filtering>

                 
                <directory>directory>

                 
                <includes>
                    <include>include>
                includes>

                
                <excludes>
                    <exclude>exclude>
                excludes>
            resource> 
        resources> 

         
        <testResources> 
             
            <testResource> 
                 
                <targetPath>targetPath> 

                 
                <filtering>filtering>

                 
                <directory>directory>

                 
                <includes>
                    <include>include>
                includes>

                
                <excludes>
                    <exclude>exclude>
                excludes> 
            testResource> 
        testResources> 

         
        <directory>directory> 

         
        <finalName>finalName> 

         
        <filters>filters> 

         
        <pluginManagement> 
             
            <plugins> 
                 
                <plugin> 
                     
                    <groupId>groupId> 

                     
                    <artifactId>artifactId> 

                     
                    <version>version> 

                     
                    <extensions>true/falseextensions> 

                     
                    <executions> 
                         
                        <execution> 
                             
                            <id>id>

                             
                            <phase>phase>

                             
                            <goals>goals> 

                             
                            <inherited>true/falseinherited> 

                             
                            <configuration>configuration>
                        execution> 
                    executions> 

                     
                    <dependencies>
                         
                        <dependency> 
                        dependency> 
                    dependencies> 

                     
                    <inherited>true/falseinherited>

                     
                    <configuration>configuration>
                plugin> 
            plugins> 
        pluginManagement> 

         
        <plugins> 
             
            <plugin> 
                 
                <groupId>groupId> 

                 
                <artifactId>artifactId> 

                 
                <version>version> 

                 
                <extensions>true/falseextensions> 

                 
                <executions> 
                     
                    <execution> 
                         
                        <id>id>

                         
                        <phase>phase>

                         
                        <goals>goals> 

                         
                        <inherited>true/falseinherited> 

                         
                        <configuration>configuration>
                    execution> 
                executions> 

                 
                <dependencies>
                     
                    <dependency> 
                    dependency> 
                dependencies> 

                 
                <inherited>true/falseinherited> 

                 
                <configuration>configuration> 
            plugin> 
        plugins>
    build> 

     
    <profiles> 
         
        <profile> 
             
            <id>id>

             
            <activation> 
                 
                <activeByDefault>true/falseactiveByDefault> 

                 
                <jdk>jdk版本,如:1.7jdk> 

                 
                <os> 
                     
                    <name> Windows XP name> 

                     
                    <family> Windows family> 

                     
                    <arch> x86 arch> 

                     
                    <version> 5.1.2600 version> 
                os> 

                 
                <property> 
                     
                    <name> mavenVersion name> 

                     
                    <value> 2.0.3 value> 
                property> 

                 
                <file> 
                     
                    <exists> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ exists> 

                     
                    <missing> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ missing> 
                file> 
            activation> 

             
            <build> 
                <defaultGoal /> 
                <resources> 
                    <resource> 
                        <targetPath>targetPath>
                        <filtering>filtering>
                        <directory>directory>
                        <includes>
                            <include>include>
                        includes>
                        <excludes>
                            <exclude>exclude>
                        excludes>
                    resource> 
                resources> 
                <testResources> 
                    <testResource> 
                        <targetPath>targetPath>
                        <filtering>filtering>
                        <directory>directory>
                        <includes>
                            <include>include>
                        includes>
                        <excludes>
                            <exclude>exclude>
                        excludes> 
                    testResource> 
                testResources> 
                <directory>directory>
                <finalName>finalName>
                <filters>filters> 
                <pluginManagement> 
                    <plugins> 
                         
                        <plugin> 
                            <groupId>groupId>
                            <artifactId>artifactId>
                            <version>version>
                            <extensions>true/falseextensions> 
                            <executions> 
                                <execution> 
                                    <id>id>
                                    <phase>phase>
                                    <goals>goals>
                                    <inherited>true/falseinherited>
                                    <configuration>configuration> 
                                execution> 
                            executions> 
                            <dependencies> 
                                 
                                <dependency> 
                                dependency> 
                            dependencies> 
                            <goals>goals>
                            <inherited>true/falseinherited>
                            <configuration>configuration>
                        plugin> 
                    plugins> 
                pluginManagement> 
                <plugins> 
                     
                    <plugin> 
                        <groupId>groupId>
                        <artifactId>artifactId>
                        <version>version>
                        <extensions>true/falseextensions> 
                        <executions> 
                            <execution> 
                                <id>id>
                                <phase>phase>
                                <goals>goals>
                                <inherited>true/falseinherited>
                                <configuration>configuration> 
                            execution> 
                        executions> 
                        <dependencies> 
                             
                            <dependency> 
                            dependency> 
                        dependencies> 
                        <goals>goals>
                        <inherited>true/falseinherited>
                        <configuration>configuration> 
                    plugin> 
                plugins> 
            build> 

             
            <modules>
                
                <module>module>
            modules> 

             
            <repositories> 
                 
                <repository> 
                    <releases> 
                        <enabled><enabled>
                        <updatePolicy>updatePolicy>
                        <checksumPolicy>checksumPolicy> 
                    releases> 
                    <snapshots> 
                        <enabled><enabled>
                        <updatePolicy>updatePolicy>
                        <checksumPolicy>checksumPolicy> 
                    snapshots> 
                    <id>id>
                    <name>name>
                    <url>url>
                    <layout>layout> 
                repository> 
            repositories> 

             
            <pluginRepositories> 
                 
                <pluginRepository> 
                    <releases> 
                        <enabled><enabled>
                        <updatePolicy>updatePolicy>
                        <checksumPolicy>checksumPolicy> 
                    releases> 
                    <snapshots> 
                        <enabled><enabled>
                        <updatePolicy>updatePolicy>
                        <checksumPolicy>checksumPolicy>
                    snapshots> 
                    <id>id>
                    <name>name>
                    <url>url>
                    <layout>layout> 
                pluginRepository> 
            pluginRepositories> 

             
            <dependencies> 
                 
                <dependency> 
                dependency> 
            dependencies> 

             
            <reports>reports> 

             
            <reporting>reporting> 

             
            <dependencyManagement> 
                <dependencies> 
                     
                    <dependency> 
                    dependency> 
                dependencies> 
            dependencyManagement> 

             
            <distributionManagement> 
            distributionManagement> 

             
            <properties /> 
        profile> 
    profiles> 

     
    <modules>
        
        <module>module>
    modules> 

     
    <repositories> 
         
        <repository> 
             
            <releases> 
                 
                <enabled><enabled> 

                 
                <updatePolicy>updatePolicy> 

                 
                <checksumPolicy>checksumPolicy> 
            releases> 

             
            <snapshots> 
                <enabled><enabled>
                <updatePolicy>updatePolicy>
                <checksumPolicy>checksumPolicy> 
            snapshots> 

             
            <id> banseon-repository-proxy id> 

             
            <name> banseon-repository-proxy name> 

             
            <url> http://192.168.1.169:9999/repository/ url> 

             
            <layout> default layout> 
        repository> 
    repositories> 

     
    <pluginRepositories> 
         
        <pluginRepository> 
        pluginRepository> 
    pluginRepositories> 

     
    <dependencies> 
        <dependency> 
             
            <groupId> org.apache.maven groupId> 

             
            <artifactId> maven-artifact artifactId> 

             
            <version> 3.8.1 version> 

             
            <type> jar type> 

             
            <classifier>classifier> 

             
            <scope> test scope> 

             
            <systemPath>systemPath> 

             
            <exclusions> 
                <exclusion> 
                    <artifactId> spring-core artifactId> 
                    <groupId> org.springframework groupId> 
                exclusion> 
            exclusions> 

             
            <optional> true optional> 
        dependency> 
    dependencies> 

     
    <reports>reports> 

     
    <reporting> 
         
        <excludeDefaults /> 

         
        <outputDirectory /> 

         
        <plugins> 
             
            <plugin> 
                 
                <groupId>groupId> 
                 
                <artifactId>artifactId> 

                 
                <version>version> 

                 
                <inherited>true/falseinherited> 

                 
                <configuration>configuration> 

                 
                <reportSets> 
                     
                    <reportSet> 
                         
                        <id>id> 

                         
                        <configuration>configuration> 

                         
                        <inherited>true/falseinherited> 

                         
                        <reports>reports> 
                    reportSet> 
                reportSets> 
            plugin> 
        plugins> 
    reporting> 

     
    <dependencyManagement> 
        <dependencies> 
             
            <dependency> 
            dependency> 
        dependencies> 
    dependencyManagement> 

     
    <distributionManagement> 
         
        <repository> 
             
            <uniqueVersion /> 
            <id> banseon-maven2 id> 
            <name> banseon maven2 name> 
            <url> file://${basedir}/target/deploy url> 
            <layout>layout> 
        repository> 

         
        <snapshotRepository> 
            <uniqueVersion /> 
            <id> banseon-maven2 id> 
            <name> Banseon-maven2 Snapshot Repository name> 
            <url> scp://svn.baidu.com/banseon:/usr/local/maven-snapshot url> 
            <layout>layout>
        snapshotRepository> 

         
        <site> 
             
            <id> banseon-site id> 

             
            <name> business api website name> 

             
            <url> 
                scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web 
            url> 
        site> 

         
        <downloadUrl /> 

         
        <relocation> 
             
            <groupId>groupId> 

             
            <artifactId>artifactId> 

             
            <version>version> 

             
            <message>message> 
        relocation> 

         
        <status>status> 
    distributionManagement> 

     
    <properties>
        <name>valuename>
    properties> 
project> 

你可能感兴趣的:(JavaEE,maven,xml,java,java-ee)