`

Maven pom.xml 如何引用外部变量

阅读更多


1.怎样使每次测试时不删除数据库中表结构?
    解答:将pom.xml配置中的如下代码屏蔽掉。



            <!--plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>hibernate3-maven-plugin</artifactId>
                                <version>2.0-alpha-2</version>
                                <configuration>
                                        <components>
                                                <component>
                                                        <name>hbm2ddl</name>
                                                        <implementation>
                                                                annotationconfiguration
                                                        </implementation>
                                                </component>
                                        </components>
                                        <componentProperties>
                                                <drop>true</drop>
                                                <jdk5>true</jdk5>
                                                <propertyfile>
                                                        target/classes/jdbc.properties
                                                </propertyfile>
                                                <skip>${maven.test.skip}</skip>
                                        </componentProperties>
                                </configuration>
                                <executions>
                                        <execution>
                                                <phase>process-test-resources</phase>
                                                <goals>
                                                        <goal>hbm2ddl</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <dependencies>
                                        <dependency>
                                                <groupId>${jdbc.groupId}</groupId>
                                                <artifactId>${jdbc.artifactId}</artifactId>
                                                <version>${jdbc.version}</version>
                                        </dependency>
                                </dependencies>
                        </plugin-->




    2.怎样使用外部配置变量?
    解答:a。在pom.xml配置文件中加入占位符



  <!-- FTP settings -->
                    <ftp.url>135.224.82.4</ftp.url>
                    <ftp.username>ls</ftp.username>
                    <ftp.password>FdbEgT+7</ftp.password>
                    <ftp.path>/data/jyf/0000/SRC/</ftp.path>
          b。在resources目录下新建文本文件ftp.properties
    ftp.url=${ftp.url}
    ftp.username=${ftp.username}
    ftp.password=${ftp.password}
    ftp.path=${ftp.path}
          c。在引用的applicationContext文件节点propertyConfigurer中添加<value>classpath:ftp.properties</value>
          d。这时就可以直接使用占位符了
    如:    <!--FTP Server-START-->
            <bean id="myFTP" class="com.xjgzinfo.app.util.MyFTP"
                    lazy-init="true" destroy-method="destroy">
                    <property name="server" value="${ftp.url}" />
                    <property name="user" value="${ftp.username}" />
                    <property name="password" value="${ftp.password}" />
                    <property name="path" value="${ftp.path}" />
            </bean>
            <!--FTP Server-END-->

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics