9

这是以下内容的后续:BlackBerry - 在自己的项目中使用自己的 JAR 文件BlackBerry - Ant 构建脚本,用于更复杂的应用程序。这个问题现在已经在下面解决了。

目标

我想要:

  1. 使用 Ant ( bb-ant-tools ) 将我的库构建到 JAR 文件中
  2. 在项目中包含该 JAR 文件
  3. 使用 Ant将该项目构建为将在设备上运行的 COD(无需外部 COD 文件)。

重要的部分是使用 Ant 来完成构建的最后阶段

我为这个问题找到的所有帖子都使用 Eclipse 进行最终构建阶段(BlackBerry 的详细信息 - 在自己的项目中使用自己的 JAR 文件)。


进步

  1. 我可以使用 Ant 将库项目构建到 JAR 中。
  2. 在 Eclipse 中,我可以将该 JAR 文件添加到项目中,并根据需要构建它(单个 COD,无外部依赖项)。它将在设备上运行。
  3. 在 Ant 中,我还可以构建依赖于一个额外的 COD 库来包含运行时代码的构建——这接近我所需要的。

问题

我可以用 Ant 构建最终项目。但生成的 COD 文件不包含我的库中的任何运行时代码

我读过的许多帖子都显示了如何使用库的额外 COD 文件来完成此操作。我想避免这种情况。

如何使用 Ant 在没有外部依赖项的情况下将 JAR 包含到我的项目中?我相信这是可能的,因为我可以使用 Eclipse 来做到这一点。


解决方法

我目前的解决方法是将我的 SDK / 库项目作为源代码(根据下面 esaj 的回答),而不是作为 JAR 文件。与 JAR 方法相比,这有一些缺点,但我有一个可以在设备上成功运行的构建。


(我希望可以通过以下一长串链接来交叉引用这个问题?)

StackOverflow 链接:

这个提供了其他链接 - 非常有用:

这些不是那么有用:

轮缘:

4

2 回答 2

4

您是否尝试过在 rapc 下的 src 部分中指向库?

例如:

<rapc ...>
  <src>
    <fileset dir="${buildDirectory}">
      <include name="src/**/*.rrh" />
      <include name="src/**/*.rrc" />
      <include name="src/**/*.java" />
      <include name="res/**/*.*" />
      <!-- Libraries -->
      <include name="lib/**/*.*" />
    </fileset>
  </src>
</rapc>
于 2012-05-17T10:36:38.733 回答
1

去年我遇到了类似的问题,我创建了一个“框架”,用作多个 BB 应用程序的基础,但遇到了多个 COD 的问题(我不记得具体是什么,比如设备拒绝安装具有相同外部 COD 的多个应用程序,如果没有先单独安装外部 COD,然后是应用程序)。由于应用程序可以单独安装(一个人可能只安装应用程序 A,另一个人可能只安装应用程序 B,而另一个人可能同时安装 A 和 B),整个框架需要包含在所有使用它的应用程序中。我使用 bb-ant-tools 编写了这个 Ant 脚本(希望我没有破坏任何东西,删除一些特定于我们的应用程序的东西和混淆包名等):

<?xml version="1.0" encoding="UTF-8"?>

<project name="${description}" default="build" basedir=".">

    <taskdef resource="bb-ant-defs.xml" classpath="lib/bb-ant-tools.jar" />

    <!-- rapc and sigtool require the jde.home property to be set -->
    <!-- NOTE: You may need to copy the signature files from Eclipse\plugins\net.rim.ejde\vmTools to the components\bin -dir 
        if the keys were installed using the Eclipse-plugin     -->
    <property name="jdehome" value="C:\BB\Eclipse\plugins\net.rim.ejde.componentpack5.0.0_5.0.0.25\components" />

    <!-- Framework source locations, these must be set correctly -->
    <property name="frameworkRes.dir" value="C:\BB\workspace\BB_Framework\res" />
    <property name="frameworkSrc.dir" value="C:\BB\workspace\BB_Framework\src\com\whatever\frame" />

    <!-- Locations for simulator, binaries, jde home, don't touch these -->
    <property name="simulator" value="${jdehome}\simulator" />
    <property name="bin" value="${jdehome}\bin" />
    <property name="jde.home" location="${jdehome}" />

    <!-- directory of simulator to copy files to -->
    <property name="simulator.home" location="${simulator}" />

    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <property name="temp.dir" location="C:\tempsrc" />

    <!-- Project specific -->
    <!-- Application title -->
    <property name="app.title" value="Application Name" />
    <property name="app.version" value="1.0.0" />
    <!-- Value to prepend before frame-class packages -->
    <property name="frame.prefix" value="appname" />
    <!-- Name of the COD to produce --> 
    <property name="cod.name" value="Appname" />

    <target name="build">
        <mkdir dir="${build.dir}" />
        <delete dir="${temp.dir}" />
        <mkdir dir="${temp.dir}" />
        <mkdir dir="${temp.dir}\${frame.prefix}" />

        <copy toDir="${temp.dir}">
            <fileset dir="${src.dir}">
                <include name="**/*.java" />
            </fileset>
        </copy>

        <copy toDir="${temp.dir}\${frame.prefix}">
            <fileset dir="${frameworkSrc.dir}">
                <include name="**/*.java" />
            </fileset>
        </copy>

        <copy toDir="${temp.dir}\res">
            <fileset dir="${frameworkRes.dir}">
                <include name="**/*" />
            </fileset>
        </copy>

        <copy toDir="${temp.dir}\res">
            <fileset dir="res">
                <include name="**/*" />
            </fileset>
        </copy>

        <!-- This replaces the package names for classes copied from under framework-directory to ${frame.prefix} -directory -->    
        <replace dir="${temp.dir}" value="${frame.prefix}">
            <include name="**/*.java"/>
            <replacetoken>com.whatever.frame</replacetoken>
        </replace>

        <rapc output="${cod.name}" srcdir="${temp.dir}" destdir="${build.dir}">
            <jdp title="${app.title}" 
                version="${app.version}" 
                vendor="Your Company"
                icon="../res/img/icon.png"
            />
        </rapc>
    </target>

    <target name="sign">
        <sigtool codfile="${build.dir}/${cod.name}.cod" />
    </target>

    <target name="clean">
        <delete dir="${build.dir}" />
    </target>

    <target name="load-simulator" depends="build">
        <copy todir="${simulator.home}">
            <fileset dir="${build.dir}" includes="*.cod,*.cso,*.debug,*.jad,*.jar" />
        </copy>
    </target>

</project>

它的作用是从当前项目复制所有 java 文件和资源,然后从框架项目复制到临时目录,在框架文件的途中替换包名称(因为它们被单独放入命名目录),这与设备也拒绝安装在相同包下具有相同类的多个应用程序有关(即,框架类,对于您的情况,这可能不是必需的)。复制和替换完成后,应用程序将使用 rapc 构建到目标构建目录。对应用程序进行签名、清理和加载到模拟器有不同的任务。希望这可以帮助。

于 2012-05-17T11:31:30.943 回答