Maven可以在这个ANT build.xml中完成我们正在做的事情

时间:2012-09-12 19:51:31

标签: java spring maven ant

Maven可以在这个ANT build.xml中完成我们正在做的事情。

  1. Takinig源代码和罐子并且发动战争
  2. 移动文件
  3. 根据属性文件值更改文件中的值
  4. 删除文件
  5. SCP WAR to server
  6. 下面是我的ANT版本。如果我能在Maven完成所有这些工作,请告诉我...谢谢

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project default="build" name="Create Runnable Jar for Project DisasterReliefBatch with Jar-in-Jar Loader">
        <!--this file was created by Eclipse Runnable JAR Export Wizard-->
        <!--ANT 1.7 is required      
                                   -->
        <property name="server.location" value="uftwfssh@6dvjvm01.uftwf.dev:/home/uftwfssh" />
        <path id="master-classpath">
            <fileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" />
        </path>
    
    
        <target name="movexml" depends="clean">
            <copy todir="${user.home}/uft-workspace/DisasterReliefBatch/bin" overwrite="true">
                <fileset dir="${user.home}/uft-workspace/DisasterReliefBatch/src" includes="*.xml" />
                <mapper type="flatten" />
            </copy>
    
            <replace file="${user.home}/uft-workspace/DisasterReliefBatch/bin/config.xml" value="defaultvalue" propertyFile="name.properties">
                <replacefilter token="os400dataSource.url" property="os400dataSource.url" />
                <replacefilter token="os400dataSource.username" property="os400dataSource.username" />
                <replacefilter token="os400dataSource.password" property="os400dataSource.password" />
    
                <replacefilter token="mysqldataSource.url" property="mysqldataSource.url" />
                <replacefilter token="mysqldataSource.username" property="mysqldataSource.username" />
                <replacefilter token="mysqldataSource.password" property="mysqldataSource.password" />
            </replace>
    
            <replace file="${user.home}/uft-workspace/DisasterReliefBatch/bin/log4j.xml" value="defaultvalue" propertyFile="name.properties">
                <replacefilter token="email.to" property="email.to" />
                <replacefilter token="email.SMTPHost" property="email.SMTPHost" />
            </replace>
        </target>
    
        <target name="clean">
            <delete dir="${user.home}/uft-workspace/DisasterReliefBatch/bin" />
        </target>
    
        <target name="compile" depends="movexml">
            <mkdir dir="${user.home}/uft-workspace/DisasterReliefBatch/bin" />
    
            <javac destdir="${user.home}/uft-workspace/DisasterReliefBatch/bin">
                <src path="${user.home}/uft-workspace/DisasterReliefBatch/src" />
                <classpath refid="master-classpath" />
            </javac>
    
        </target>
    
        <target name="build" depends="compile">
            <jar destfile="${user.home}/DRB.jar">
                <manifest>
                    <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                    <attribute name="Rsrc-Main-Class" value="org.uftwf.batch.MainBatch" />
                    <attribute name="Class-Path" value="." />
                    <attribute name="Rsrc-Class-Path" value="./ commons-logging-1.1.1.jar mysql-connector-java-5.0.5.jar jt400Native.jar log4j-1.2.14.jar org.springframework.beans-3.0.6.RELEASE.jar org.springframework.core-3.0.6.RELEASE.jar org.springframework.jdbc-3.0.6.RELEASE.jar org.springframework.context-3.0.6.RELEASE.jar org.springframework.context.support-3.0.6.RELEASE.jar org.springframework.aspects-3.0.6.RELEASE.jar org.springframework.oxm-3.0.6.RELEASE.jar org.springframework.instrument.tomcat-3.0.6.RELEASE.jar commons-codec-1.4.jar httpclient-4.1.2.jar httpclient-cache-4.1.2.jar httpcore-4.1.2.jar httpmime-4.1.2.jar itext-xtra-5.1.3.jar itextpdf-5.1.3.jar jt400.jar junit-4.10.jar org.springframework.aop-3.0.6.RELEASE.jar org.springframework.asm-3.0.6.RELEASE.jar org.springframework.expression-3.0.6.RELEASE.jar org.springframework.instrument-3.0.6.RELEASE.jar org.springframework.jms-3.0.6.RELEASE.jar org.springframework.orm-3.0.6.RELEASE.jar org.springframework.test-3.0.6.RELEASE.jar org.springframework.transaction-3.0.6.RELEASE.jar org.springframework.web-3.0.6.RELEASE.jar org.springframework.web.portlet-3.0.6.RELEASE.jar org.springframework.web.servlet-3.0.6.RELEASE.jar org.springframework.web.struts-3.0.6.RELEASE.jar mail.jar mailapi.jar smtp.jar" />
                </manifest>
    
                <zipfileset src="${user.home}/jar-in-jar-loader.zip" />
                <fileset dir="${user.home}/uft-workspace/DisasterReliefBatch/bin" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="commons-logging-1.1.1.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="mysql-connector-java-5.0.5.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="jt400Native.jar" />
                <fileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch" includes="log4j-1.2.14.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.beans-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.core-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.jdbc-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.context-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.context.support-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.aspects-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.oxm-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.instrument.tomcat-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="commons-codec-1.4.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="httpclient-4.1.2.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="httpclient-cache-4.1.2.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="httpcore-4.1.2.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="httpmime-4.1.2.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="itext-xtra-5.1.3.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="itextpdf-5.1.3.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="jt400.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="junit-4.10.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.aop-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.asm-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.expression-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.instrument-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.jms-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.orm-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.test-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.transaction-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.web-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.web.portlet-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.web.servlet-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="org.springframework.web.struts-3.0.6.RELEASE.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="mail.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="mailapi.jar" />
                <zipfileset dir="${user.home}/uft-workspace/DisasterReliefBatch/lib" includes="smtp.jar" />
            </jar>
    
    
        </target>
    
        <target name="promote" depends="build">
            <input message="New version is going to be updated to 6dvjvm01 continue (y/n)?" validargs="y,n" addproperty="do.delete" />
    
            <condition property="do.abort">
                <equals arg1="n" arg2="${do.delete}" />
            </condition>
    
            <fail if="do.abort">Build aborted by user.</fail>
    
            <scp file="${user.home}/DRB.jar" todir="${server.location}" keyfile="${user.home}/.ssh/id_rsa" />
        </target>
    
        <target name="run" depends="build">
            <java jar="${user.home}/DRB.jar" fork="true" />
        </target>
    
        <target name="run-count" depends="build">
            <java jar="${user.home}/DRB.jar" fork="true">
                <arg value="count" />
            </java>
        </target>
    </project>
    

2 个答案:

答案 0 :(得分:1)

烨。基于属性的注入在maven中称为“资源过滤”。请参阅http://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-description.html

在maven项目中很少需要移动文件;您只需遵循约定或为编译器/ war-assembly插件声明其他“源”路径。

我从未使用maven直接将war文件scp到服务器,但我会将此线程作为资源阅读:Maven copy local file to remote server using SSH

作为最后的努力,maven还有一个'antrun'插件,允许你在必要时运行自定义ant任务。但是,在您的情况下,不应该要求它。

答案 1 :(得分:0)

对于“SCP War to server”,您可以查看http://mojo.codehaus.org/wagon-maven-plugin/upload-mojo.html

手动尝试:mvn org.codehaus.mojo:wagon-maven-plugin:1.0:upload -Dwagon.url=scp://username:userpassword@myserver -Dwagon.fromDir=target -Dwagon.includes=*.ear -Dwagon.toDir=/home/elisabetta

在这两种情况下,请务必为Wagon添加SSH扩展名: <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.8</version> </extension> </extensions>