前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ant 简介-下

Ant 简介-下

作者头像
acc8226
发布2022-06-23 14:38:50
2460
发布2022-06-23 14:38:50
举报
文章被收录于专栏:叽叽西

Ant官方各标签参考手册

http://ant.apache.org/manual/

mail 标签发送邮件

需要预先下载 jar 包 javax.mail-api.jar | mail task with MIME encoding https://javaee.github.io/javamail/

否则会报错

代码语言:javascript
复制
D:\Ant\AutoPackage\build.xml:144: java.lang.NoClassDefFoundError: com/sun/mail/util/FolderClosedIOException
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:458)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.apache.tools.ant.Task.perform(Task.java:350)
        at org.apache.tools.ant.Target.execute(Target.java:449)
        at org.apache.tools.ant.Target.performTasks(Target.java:470)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:834)
        at org.apache.tools.ant.Main.startAnt(Main.java:223)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.FolderClosedIOException
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 20 more

简单实例

代码语言:javascript
复制
  <target name="mail">
    <mail mailhost="smtp.163.com" mailport="25" subject="Build successful" charset="utf-8" user="YOUR_EMAIL@163.com" password="YOUR PASSWORD">
      <from address="YOUR_EMAIL@163.com"/>
      <to address="1334598467@qq.com"/>
      <message>some international text</message>
    </mail>
  </target>

AntCall

利用AntCall Task实现target间调用时传递参数的实例 当需要从一个target传递参数到被调用的target时,可以使用<param> 类型进行传递。当然也可以在target中定义property来实现,与Java中的方法调用时传递参数相似

代码语言:javascript
复制
  <target name="targetA">
    <!-- 通过property传递  -->
    <property name="prop" value="prop property" />
    <antcall target="targetB">
      <!-- 通过antcall设定param实现  -->
      <param name="path1" value="path1 param" />
    </antcall>
  </target>

  <target name="targetB" depends="init">
    <echo message="In targetB" />
    <echo message="path1=${path1}" />
    <echo message="prop=${prop}" />
  </target>

audio

Plays a sound file at the end of the build, according to whether the build failed or succeeded. You can specify either a specific sound file to play, or, if a directory is specified, the <sound> task will randomly select a file to play. Note: At this point, the random selection is based on all the files in the directory, not just those ending in appropriate suffixes for sound files, so be sure you only have sound files in the directory you specify.

代码语言:javascript
复制
<sound>
    <success source="${user.home}/sounds/bell.wav"/>
    <fail source="${user.home}/sounds/ohno.wav" loops="2"/>
  </sound>

注意: 在taget内<antcall target="playsound" />不生效不知为何

代码语言:javascript
复制
  <!-- antcall调用没反应, depends却可以 -->
  <target name="playsound">
    <sound>
      <success source="audio/ring.wav"/>
    </sound>
  </target>

mail

代码语言:javascript
复制
  <target name="mail">
    <mail mailhost="smtp.163.com" mailport="25" subject="Build successful" charset="utf-8" user="sbf15270837834@163.com" password="xxxxx">
      <from address="sbf15270837834@163.com" name="往事随风"/>
      <to address="1334598467@qq.com" name="飞翔的企鹅"/>
      <message>some international text</message>
      <!-- <attachments>
        <fileset dir="${outDir}">
          <include name="*.apk"/>
        </fileset>
      </attachments> -->
    </mail>
  </target>

ftp

代码语言:javascript
复制
  <target name="ftp1" description="将 demo.apk上传到技术环境">
    <ftp server="10.1.61.123" remotedir="/opt/wasAppServer/profiles/AppSrv01/installedApps/test42Node01Cell/insure-pad_war.ear/demo.war/1" userid="root" password="abc@/1py">
      <fileset dir="C:/Users/hp/Desktop/demo_apk">
        <include name="android.keystore" />
      </fileset>
    </ftp>
  </target>

build 命令

代码语言:javascript
复制
-help, -h              print this message and exit
-projecthelp, -p       print project help information and exit
-version               print the version information and exit
-buildfile <file>      use given buildfile
  -file    <file>              ''
  -f       <file>              ''
-D<property>=<value>   use value for given property
  • 发现使用-projecthelp,命令 只有在project有内部标签 或者target有该属性 description 才会现在

load高级用法

代码语言:javascript
复制
    <loadresource property="newApkName" encoding="UTF-8">
      <string value="${itemAppName}" />
      <filterchain>
        <tokenfilter>
          <!-- 巧妙将后缀.apk加上了时间 -->
          <replaceregex pattern="\.apk" replace="_aligned.apk" flags="g" />
        </tokenfilter>
      </filterchain>
    </loadresource>

参考

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-06-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Ant官方各标签参考手册
  • mail 标签发送邮件
  • AntCall
  • audio
  • mail
  • ftp
  • build 命令
  • 参考
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档