日常填坑系列-Maven-Pom.xml配置

1、父模块中的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.demo</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>jfinaldemo</module>
    </modules>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.jfinal</groupId>
                <artifactId>jfinal</artifactId>
                <version>3.4</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

2、子模块中的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>

    <artifactId>jfinal-demo</artifactId>

    <!-- 打包的机制,默认为jar如jar, pom, war, maven-plugin, ejb, ear, rar, par, -->
    <packaging>war</packaging>
    <!--继承一个父模块-->
    <parent>
        <artifactId>parent</artifactId>
        <groupId>com.uinnova.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <!-- 为pom定义一些常量,在pom中的其它地方可以直接引用 使用方式 如下 :${jfinal.version} -->
    <properties>
        <jfinal.version>3.4</jfinal.version>
    </properties>
    <!--配置依赖-->
    <dependencies>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
            <!--引用properties配置的常量值-->
            <version>${jfinal.version}</version>
            <!-- maven认为,程序对外部的依赖会随着程序的所处阶段和应用场景而变化,所以maven中的依赖关系有作用域(scope)的限制。 -->
            <!--scope包含如下的取值:compile(编译范围)、provided(已提供范围,意思就是编译阶段和测试阶段依赖,运行时不依赖)、runtime(运行时范围)、test(测试范围)、system(系统范围) -->
            <scope>compile</scope>
            <!-- 屏蔽依赖关系。 比如项目中使用的libA依赖某个库的1.0版,libB依赖某个库的2.0版,现在想统一使用2.0版,就应该屏蔽掉对1.0版的依赖 -->
            <exclusions>
                <exclusion>
                    <groupId>xx</groupId>
                    <artifactId>xx</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>


    <build>
        <!-- 产生的构件的文件名,默认值是${artifactId}-${version}。 -->
        <finalName>jfinalDemo</finalName>

        <!-- 构建产生的所有文件存放的目录,默认为${basedir}/target,即项目根目录下的target -->
        <directory>${basedir}/target</directory>

        <resources>
            <resource>
                <!--描述存放资源的目录,该路径相对POM路径-->
                <directory>${basedir}/src/main/webapp/</directory>

                <!--描述了资源的目标路径。该路径相对target/classes目录,如果你只是想把资源放到源码目录结构里,就不需要该配置。 -->
                <!--举个例子,如果你想资源在特定的包里(org.apache.maven.messages),你就必须该元素设置为org/apache/maven/messages。 -->
                <!--不填相当于放在target/classes,和com包同级-->
                <targetPath>com</targetPath>
                <!--是否使用参数值代替参数名。参数值取自properties元素或者文件里配置的属性,文件在filters元素里列出。 -->
                <filtering>true</filtering>

                <!--包含的模式列表 -->
                <includes>
                    <include>**/*.html</include>
                </includes>

                <!--排除的模式列表 如果<include>与<exclude>划定的范围存在冲突,以<exclude>为准 -->
                <excludes>
                    <exclude>jdbc.properties</exclude>
                </excludes>

            </resource>
        </resources>


        <plugins>
            <!--配置项目所用的Jdk版本-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <target>1.8</target>
                    <source>1.8</source>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!--配置项目Tomcat插件启动-->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>80</port>
                    <path>/</path>
                </configuration>
                <!--在构建生命周期中执行一组目标的配置。每个目标可能有不同的配置。 -->
                <executions>
                    <execution>
                        <id>run</id>
                        <!--执行生命周期,会触发下面配置的插件的目标-->
                        <phase>package</phase>
                        <!--配置的执行目标,在对应的插件中查看-->
                        <goals>
                            <goal>run-war-only</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>
</project>

3、配置文件实战

  •    dependencyManagement和pluginManagement
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
            <version>3.4</version>
        </dependency>
    </dependencies>
</dependencyManagement>

父模块指定了jfinal的版本,在子模块只需要引入

<dependencies>
    <dependency>
        <groupId>com.jfinal</groupId>
        <artifactId>jfinal</artifactId>
    </dependency>
</dependencies>

子模块就会引入3.4的依赖,如果,子模块配置了对应的版本,子模块的为主。

denpendencyManagement是用于管理项目jar包依赖,pluginManagement是用于管理plugin。子项目可以引用父模块中的已经配置好版本的jar和plugin使用,而不用指定版本,也是为了快统一管理。

  • build

 

<filters>
    <filter>jar.properties</filter>
</filters>

filters:用于定义指定filter属性的位置,例如filter元素赋值jar.properties,这个文件里面定义name=value,在pom中通过${name}引用。默认的filter目录 是${basedir}/src/main/fiters/ 

在build下的inherited标签是指是否让子pom继承,ture or false 默认为true. 

常用的配置,还需要都在上述配置文件中配置了,自己实战加参考https://www.cnblogs.com/mingforyou/p/4494713.html 写出了自己总结

转载于:https://my.oschina.net/u/3505620/blog/1819444

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值