hnakamur’s blog

ものすごい勢いで忘れる私のために未整理でもいいからとりあえずメモ

ラベル ant の投稿を表示しています。 すべての投稿を表示
ラベル ant の投稿を表示しています。 すべての投稿を表示

2011-03-30

Antからmavenを実行するサンプル

参考:

事前準備:上記のサイトからmaven-ant-tasks-2.1.1.jarをダウンロードして${ANT_HOME}/libにコピー。

<?xml version="1.0" encoding="UTF-8"?>
<project name="necs" basedir="." default="help"
    xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <property file="build.properties"/>
  <property name="maven.local.repo.dir" value="${user.dir}/localRepository"/>

  <target name="help">
    <echo>
      Usage: ant build|help
    </echo>
  </target>

  <artifact:localRepository id="localRepo" path="${maven.local.repo.dir}"/>

  <macrodef name="mvn_clean_install_no_test">
    <attribute name="dir" />
    <sequential>
      <artifact:mvn pom="@{dir}/pom.xml" fork="yes" failonerror="true">
        <localRepository refid="localRepo"/>
        <arg value="-Dmaven.test.skip=true"/>
        <arg value="clean"/>
        <arg value="install"/>
      </artifact:mvn>
    </sequential>
  </macrodef>


  <target name="build">
    <mvn_clean_install_no_test dir="SampleApp" />
  </target>
</project>

artifact:mvnタスクはJavaタスクを継承しているのでfork属性が使えます。-Dname=valueを有効にするためにはforkする必要があるのでfork="true"を指定しています。

2011-03-24

antで踏み台サーバ経由でscp

ローカルからリモートにコピー。
<sshsession host="${ladder_host}"
    trust="true"
    username="${username}"
    keyfile="${keyfile}"
    passphrase="${passphrase}" >
    <localtunnel lport="${tunnel_port}" rhost="${target_host}" rport="22"/>
  <sequential>
    <scp trust="true"
        keyfile="${keyfile}"
        passphrase="${passphrase}"
        localFile="hoge2"
        remoteToFile="admin@localhost:hoge2"
        port="${tunnel_port}" />
  </sequential>
</sshsession>
ファイルの更新日時は現在の日時になります。

リモートからローカルにコピー。
<sshsession host="${ladder_host}"
    trust="true"
    username="${username}"
    keyfile="${keyfile}"
    passphrase="${passphrase}" >
  <localtunnel lport="${tunnel_port}" rhost="${target_host}" rport="22"/>
  <sequential>
    <scp trust="true"
        keyfile="${keyfile}"
        passphrase="${passphrase}"
        port="${tunnel_port}"
        remoteFile="${username}@localhost:hoge"
        localToFile="hoge"
        preserveLastModified="true"/>
  </sequential>
</sshsession>
こちら向きはpreserveLastModified="true"を指定すればファイルの更新日時を維持出来ます。

2011-03-18

antでsshのサンプル

予め$[ANT_HOME}/libにjsch-0.1.44.jarを置いておく。

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="ssh_test" basedir="." default="sshtest1">
  <xmlproperty file="deploy.properties.xml"
      keepRoot="false"
      semanticAttributes="true"/>
  <target name="sshtest1">
    <sshexec host="host1.example.com"
        trust="true"
        username="${username}"
        keyfile="${keyfile}"
        passphrase="${passphrase}"
        command="whoami"/>
  </target>
</project>

deploy.properties.xml
<properties>
  <username>you</username>
  <keyfile>${user.home}/.ssh/id_rsa</keyfile>
  <passphrase>your_passpharse</passphrase>
</properties>

ブログ アーカイブ