我无法为我们的制作应用创建Ant构建脚本。
我一直在阅读很多关于Ant和bb-ant-tools的内容。我已经关注了Ant& amp;上的许多stackoverflow问题。 BB(在评论中引用以“链接”问题)。我想帮助一个比通常的“Hello World!”更复杂的脚本。风格的应用。我当前的构建过程完全在Eclipse中运行,并手动完成。
对于这个问题,我想问如何使用Ant来构建一个使用2个(或更多个)不同库项目(也需要构建)的项目,而根本不使用Eclipse?
我安装了Ant,bb-ant-tools。我建了&在设备上部署了一个基本的Hello World,使用这些工具遵循基本示例。我创建了一个构建脚本和一些属性文件;但是当我运行脚本时,最终产品无法在手机上运行(手机用户界面在启动屏幕上冻结)。
我有3个构建脚本,每个库一个,主应用程序一个。这些是相同的,除了项目名称(并且可以在某个时候组合成一个常见的导入脚本)。 3个java项目中的每一个都有一个与之相关的Ant属性文件。我还使用3个常用属性文件来定义常量,在JDE&上存储信息。代码签名密码。
common.properties:
jde.home=C:/development/tools/bb-jde/jde4.5/components
sigtool.jde = ${jde.home}
sigtool.password = xxx_pass_xxx
project.properties(对于SOAP库):
output=MySOAP
type=midlet
project.properties(用于内部SDK库):
output=MySDK
type=midlet
更新1:自初始发布以来,我更新了库属性文件。以前我设置了type=library
(基于RIM文档)。根据我在这篇文章(BlackBerry - use own JAR file in own project)中概述的研究,我尝试更改为type=midlet
。这样可以获得更好的结果(至少在我的平台BB JDE 5.0上)。
project.properties(对于我的应用):
output=MyApp
title=App
type=cldc
vendor=Richard
version=1.0.7
description=A nice app
icon=icon.png
build.xml(除了顶部的名称以外,两个库脚本都没有在import.jars中声明的文件集):
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="MyApp" default="build">
<!-- BLACKBERRY ANT TOOLS -->
<property name="bb-ant-tools.home" location="C:/development/tools/bb-ant-tools" />
<taskdef resource="bb-ant-defs.xml" classpath="${bb-ant-tools.home}/bb-ant-tools.jar" />
<!-- CONFIG FILES -->
<property file="${common.basedir}/common.properties" />
<property prefix="project" file="project.properties" />
<!-- FOLDERS -->
<property name="dest.dir" location="build" />
<!-- this is empty in the library scripts -->
<path id="import.jars">
<fileset dir="../MySDK/build" includes="*.jar" />
<fileset dir="../MySOAP/build" includes="*.jar" />
</path>
<path id="src.files">
<fileset dir="src" includes="**/*" />
<fileset dir="res" includes="**/*" />
</path>
<!-- TARGET ACTIONS -->
<target name="build" depends="">
<mkdir dir="${dest.dir}" />
<!-- work around a bug requiring app icons to be in the output folder -->
<copy file="${basedir}/res/icon.png" tofile="${dest.dir}/icon.png" />
<rapc
jdehome="${jde.home}"
output="${project.output}"
destdir="${dest.dir}" >
<import refid="import.jars" />
<src refid="src.files" />
<jdp file="${basedir}/project.properties" />
</rapc>
</target>
<target name="sign" depends="build">
<sigtool
codfile="${dest.dir}/${project.output}.cod"
jdehome="${sigtool.jde}"
password="${sigtool.password}" />
</target>
<target name="clean">
<delete dir="${dest.dir}" />
</target>
</project>
更新2:自最初发布以来,我更新了build.xml
。目标build
现在将应用程序图标复制到构建输出文件夹(${dest.dir}
)以解决bb-ant-tools / rapc中的错误。
所以这是一个非常简单的Ant脚本,除了:
FWIW我找到了以下受欢迎的资源,并列出它们以便它们不需要作为答案添加,并帮助将来寻找信息的任何人:
以及stackoverflow上的许多答案 - 请参阅下面的评论
答案 0 :(得分:1)
这是我在多个项目中使用的。
<macrodef name="compile">
<attribute name="buildversion" />
<attribute name="description" />
<sequential>
<mkdir dir="${build.dir}" />
<rapc output="${cod.name}_bbminterface" destdir="${build.dir}" verbose="false" quiet="true" nowarn="true">
<src>
<fileset dir="${bbminterface.src.dir}"/>
</src>
<import location="./lib/net_rim_bb_qm_platform.jar" />
<jdp type="library" title="${app.name}_bbminterface" vendor="my vendor" version="@{buildversion}">
<entry title="${app.name}_bbminterface" description=""/>
</jdp>
</rapc>
<rapc output="${cod.name}_bbmimpl" destdir="${build.dir}" verbose="false" quiet="true" nowarn="true">
<src>
<fileset dir="${bbmimpl.src.dir}"/>
</src>
<import location="./lib/net_rim_bb_qm_platform.jar" />
<import location="${build.dir}/${cod.name}_bbminterface.jar" />
<jdp type="library" title="${app.name}_bbmimpl" vendor="my vendor" version="@{buildversion}" runonstartup="true" startuptier="6">
<entry title="${app.name}_bbmimpl" description="" runonstartup="true" startuptier="6"/>
</jdp>
</rapc>
<rapc output="${cod.name}" destdir="${build.dir}" verbose="false">
<src>
<fileset dir="${tmpsrc.dir}" />
</src>
<src>
<fileset dir="${res.dir}" />
</src>
<src>
<fileset file="${lib.dir}/paymentapi.jar" />
</src>
<import location="./lib/net_rim_bb_qm_platform.jar" />
<import location="${build.dir}/${cod.name}_bbminterface.jar"/>
<jdp type="cldc" title="${app.name}" vendor="my vendor" icon="../res/icon.png" version="@{buildversion}" description="@{description}" startuptier="7" ribbonposition="0">
<entry title="${app.name}" icon="../res/icon.png" description="@{description}" runonstartup="true" arguments="boot" systemmodule="true" startuptier="7" ribbonposition="0" />
<entry title="${app.name}" icon="../res/icon.png" description="@{description}" arguments="daemon" runonstartup="true" systemmodule="true" startuptier="7" ribbonposition="0" />
</jdp>
</rapc>
</sequential>
</macrodef>
这是编译代码。我们正在编译一些库,然后编译应用程序,链接刚刚创建的库。
然后签名:
<target name="sign" description="Sign the cod file">
<sigtool codfile="${build.dir}/${cod.name}_bbminterface.cod" password=""/>
<sigtool codfile="${build.dir}/${cod.name}_bbmimpl.cod" password=""/>
<sigtool codfile="${build.dir}/${cod.name}.cod" password="" />
</target>
然后上传到我们的OTA服务器:
答案 1 :(得分:1)
要从我的主构建文件中回答关于触发包含项目的构建的问题,解决方案是使用subant
任务,这是一个标准的Ant命令。
例如,下面的代码(我忘记了从中复制它的地方,但它不是我的,它确实有效)将触发每个提供的文件夹中的build.xml文件,并将运行{{1}在该构建文件中的目标。
export-all
它要求将名为 <subant target="export-all">
<dirset dir="${basedir}/.." includes="${project.deps}" />
<property name="export.dir" location="build/lib" />
</subant>
的属性声明为以逗号分隔的文件夹列表。 project.deps
的定义是从主build.xml中回顾一个文件夹,并在dirset
中查找每个子文件夹。
Ant会在每个文件夹中找到build.xml文件,然后运行它,寻找project.deps
目标。
在每个新的export-all
子任务中,将设置属性export-all
,这是您可以将主build.xml中的信息传递到子任务中。
答案 2 :(得分:1)
为了维护资源结构而不是将'res'文件夹添加为源文件夹,请执行以下操作:
使用ANT'jar'命令创建所有资源的临时jar文件:
<jar destfile="temp/@{brand}/res.jar"
basedir="../@{brand}/res"
compress="false"
filesonly="false"
includes="**/*"/>
在rapc命令的'src'元素中添加临时jar作为源元素:
<fileset dir="temp/@{brand}" includes="res.jar"/>
答案 3 :(得分:0)
我希望您不要忘记将您的app cod与您的app cod一起运送给最终用户。因为否则应用程序将无效。
关于触发库构建 - 我只在必要时更喜欢构建库 - 代码或依赖项已更改。
关于你的解决方案我只有bat文件,我会用不同的build.xml文件和正确的当前文件触发ant三次(因为你的ant脚本有相对的目录)。所以它会像:
cd librarydir1
ant
cd librarydir2
ant
cd appfolder
ant
答案 4 :(得分:0)
我看到了关于如何在Dhiral对Joe's answer的评论中保存资源目录结构的问题。几天前,我在评论中找到了解决方法(Blackberry Development with Ant & Eclipse):
yuri wrote:
I found a way
You just need to copy the resources temporarily to the output folder, and delete them
after the build is over. The key is that the resources must be in the working folder
of the compiler.
Posted 18 Jan 2008 at 5:08 pm ¶