日期:2014-05-19  浏览次数:20736 次

结合Maven2进行J2EE项目构建(二)
开发人员要使用内部仓库,只需修改本地工程pom.xml ,在 repository 配置后加上:

<repository>
      <id>companyName</id>
      <url>http:// ${ip}/maven</url>
</repository>




3.每日构建
    为了保证项目质量,尽早的发现项目中的bug,我们需要每日对系统进行构建,这也是我们使用maven的初衷之一,maven的几个命令就可帮助我们完成这项任务,当然我们可以使用持续构建工具与maven结合实现定时自动构建。构建方式:


mvn test
mvn package
mvn install




maven 会自动编译,测试,运行所有的testcase,这也要求我们的开发人员一定要按照规则编写单元测试代码,否则每日构建的意义就不大了。appfuse框架中提供了很好的单元测试代码,包括针对数据库层,业务逻辑层,web展示层等等,如果我们能很好的编写这些单元测试,那么对于系统后续的缺陷管理和控制是大有裨益的。

构建完成后或构建时需要对最新版本的项目进行部署,便于次日安排测试人员进行测试,maven提供多多种部署方式,在 pom.xml进行项目的部署配置,不同的部署方式根据协议的不同,配置方式也有所差异:
以文件方式部署

<project>
        [...]
        <distributionManagement>
            <repository>
                <id>proficio-repository</id>
                <name>Proficio Repository</name>
                <url>file://${basedir}/target/deploy</url>
            </repository>
        </distributionManagement>
        [...]
    </project>




以SSH2方式部署

<project>
        [...]
        <distributionManagement>
            <repository>
                <id>proficio-repository</id>
                <name>Proficio Repository</name>
                <url>scp://sshserver.yourcompany.com/deploy</url>
            </repository>
            </distributionManagement>
        [...]
    </project>




以SFTP方式部署

<project>
    [...]
    <distributionManagement>
        <repository>
            <id>proficio-repository</id>
            <name>Proficio Repository</name>
            <url>sftp://ftpserver.yourcompany.com/deploy</url>
        </repository>
    </distributionManagement>
    [...]
    </project>



以扩展SSH方式部署
 
目前为止上述3中方式已经被Maven包含,所以只要 distributionManagement就可以了,但是使用扩展SSH命令部署的话你不仅需要配置distributionManagement还需要一个build extension,如下
 
<project>
        [...]
        <distributionManagement>
            <repository>
                <id>proficio-repository</id>
                <name>Proficio Repository</name>
                <url>scpexe://sshserver.yourcompany.com/deploy</url>
            </repository>
        </distributionManagement>
        <build>
            <extensions>
                <extension>
                    <groupId>org.apache.maven.wagon</groupId>
                    <artifactId>wagon-ssh-external</artifactId>
                    <version>1.0-alpha-6</version>
                </extension>
            </extensions>
        </build>
        [...]
    </project>



    The build extension specifies the use of the Wagon external SSH provider, which does the work of moving your files to the remote server. Wagon is the general purpose transport mechanism used throughout Maven.
The build extension specifies the use of the Wagon external SSH provider, which does the work of moving your files to the remote server. Wagon is the general purpose transport mechanism used throughout Maven.

以FTP方式部署

<project>
        [...]
        <distributionManagement>
        <repository>
            <id>proficio-repository</id>
            <name>Proficio Repository</name>
            <url>ftp://ftpserver.yourcompany.com/deploy</