zoukankan      html  css  js  c++  java
  • 关于maven的一些记录

    一、关于引入配置文件的问题。

    如果在maven中引入配置文件,则需要有两个部分组成。1.在pom.xml中指定配置文件。2.在maven的setting.xml中指定

    如在pom.xml中引入开发环境和正式环境的配置文件:

    <profiles>
            <profile>
                <id>common</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <web.work.model>normal</web.work.model>
                    <config.root>/opt/pay/config/basis/ifp</config.root>
                    <project.build.sourceEncoding>
                        UTF-8
                    </project.build.sourceEncoding>
                </properties>
            </profile>
            <profile>
                <id>local</id>
                <activation>
                    <property>
                        <name>env</name>
                        <value>local</value>
                    </property>
                </activation>
                <properties>
                    <web.work.model>local</web.work.model>
                    <config.root>${env_conf_home}/base/basis/ifp</config.root>
                    <project.build.sourceEncoding>
                        UTF-8
                    </project.build.sourceEncoding>
                </properties>
            </profile>
        </profiles>

    第一个为正式环境,默认的会是用到。第二个用的是开发环境。

    在maven的setting.xml中指定用那个环境,如下:

    <profiles>
            <profile>
                <id>local</id>

                 <properties>
                    <env_conf_home>E:/loan/codes/config</env_conf_home>
                </properties>
            </profile>
        </profiles>

    <activeProfiles>
            <activeProfile>local</activeProfile>
    </activeProfiles>

    可以确定的是用local。

    ${env_conf_home}也是在setting.xml中配置的。

    二、在pom.xml中定义变量。如

            <properties>

         <abc.version>1.0.0</abc.version>

    </properties>

    在pom.xml及子pom.xml中就可以引用这个版本号了。通过

    ${abc.version}

    三、父pom.xml及子pom.xml的关系

    <packaging>pom</packaging>

    如父pom.xml为:

    <groupId>com.yhp.abc</groupId>
    <artifactId>abc-parent</artifactId>
    <version>3.0.0-SNAPSHOT</version>

    <modules>
    <module>def</module>
    </modules>

    def为主pom.xml下的文件夹,并到其下面中子pom.xml文件。

    def

    pom.xml

    则子pom.xml对父pom.xml的引用方法为:

    <parent>

    <groupId>com.yhp.abc</groupId>
    <artifactId>abc-parent</artifactId>
    <version>3.0.0-SNAPSHOT</version>

    </parent>

    四、父pom.xml及子pom.xml的继承关系

    如果在父pom.xml中定义如下:

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

    则子pom.xml会继承所用<dependencies>的依赖。

    如果添加上<dependencyManagement>,如

    <dependencyManagement>
        <dependencies>
                <!--spring frame -->
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                .......
         </dependencies>
    </dependencyManagement>

    则子pom.xml不会继承。如果需要用,则需要添加上。如下:

    <dependencies>
                <!--spring frame -->
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                </dependency>
                .......
    </dependencies>

    但是不需要加上版本号。他会继承父pom.xml中的版本。这样可以对版本好进行统一管理。

    五、关于scope

    <scope>provided</scope>或<scope>compile</scope>。

    默认为compile即,此jar在编译测试以及容器中都需要此jar。如果是provided时,只是在编译,测试的时候用到此jar,在运行的时候,容器中已经由此jar包了。如tomcat自带的jar中已经包含了这个jar

  • 相关阅读:
    Elispse快捷键
    cannot connect to daemon at tcp:5037: cannot connect to 127.0.0.1:5037: 由于目标计算机积极拒绝,无法连接。 (10061)
    android studio如何连接夜神模拟器
    Default Activity Not Found解决方法
    Android ANR log trace日志文件分析
    使用trace文件分析ANR
    ANR日志分析
    并发容器
    git上tag的一些操作
    final关键字与不变性
  • 原文地址:https://www.cnblogs.com/yanghuiping/p/4798343.html
Copyright © 2011-2022 走看看