BlackBerry:在 Ant 脚本中从 JAR 源文件创建 COD [英] BlackBerry: create COD from JAR source file in Ant script

查看:20
本文介绍了BlackBerry:在 Ant 脚本中从 JAR 源文件创建 COD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 Ant(bb-ant-tools)编译将 JAR 文件转换为 COD?即没有其他源文件

<小时>

原因

最终,我需要一个脚本来运行 Jar Jar Links (jarjar) 在构建期间,解决在多个应用程序中使用我们的 sdk 的命名空间问题.Jarjar 将 JAR 文件作为输入,我假设它输出的是 JAR 文件.

所以要在 bb-ant-tools 构建中运行 jarjar,我需要知道如何将该输出 JAR 编译成 COD.

我只关注问题的这一部分,以尽量减少其他可能的错误来源.一旦我掌握了将 JAR 构建为 COD 的能力,我将尝试 jarjar 步骤.

进展

1) 我可以将我的项目构建成一个有效的 COD,签名并在设备上运行.

2) 为了包含 sdk 代码,我目前将源文件夹添加到主项目构建中.(将来我想知道如何将库作为 JAR 包含在构建中 - BlackBerry - Ant 脚本,用于在没有外部依赖的项目中包含 JAR)

3) 此步骤的输出包括常用文件:

  • MyApp.cod(如果我签名,它会在设备上完美运行)
  • MyApp.csl
  • MyApp.cso
  • MyApp.debug
  • MyApp.jad
  • MyApp.jar(我想在这个上运行 jarjar)
  • MyApp.rapc

4) 我尝试运行第二个构建,采用上述 JAR 文件并将其用作 rapc 调用中的唯一源文件.为此,我将 rapcsrc 标记指向仅包含我的 JAR 文件的文件夹.

在构建的最后部分,当 rapc adding 文件时,我收到错误:

 java.util.zip.ZipException:重复条目:MyApp-1.cod

(以下已编辑构建输出中错误的完整详细信息)

我可以看到这是 rapc 第二次尝试添加此文件.我不明白为什么,因为 JAR 中只有该文件的一个副本.

<小时>

构建输出(使用 ...etc 编辑以使其可读)

构建:[mkdir] 跳过 C:\development\ant\new_test\MyApp\build 因为它已经存在.[复制] 复制 1 个文件到 C:\development\ant\new_test\MyApp\build[复制] 复制 C:\development\ant\new_test\MyApp\icon.png 到 C:\development\ant\new_test\MyApp\build\icon.png[rapc] 将 1 个源文件编译为 MyApp.cod[rapc] 使用参数执行 'C:\Java\jdk1.6.0_24\jre\bin\java.exe':[rapc] '-classpath'[rapc] 'C:\Java\jdk1.6.0_24\lib\tools.jar;C:\development\tools\bb-jde\jde5.0\components\bin\rapc.jar'[rapc] 'net.rim.tools.compiler.Compiler'[rapc] '-详细'[rapc] 'import=C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar'[rapc] '代号 = MyApp'[rapc] 'MyApp.rapc'[rapc] '@sources.txt'[说唱][rapc] 可执行文件和参数周围的 ' 字符是[rapc] 不是命令的一部分.[rapc] 设置环境变量:PATH=........etc[rapc] 阅读资源:MyApp.cod...等等[rapc] 解析类文件:com/MyApp/ui/views/WelcomeBar.class...等等[rapc] 解析导入:C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar(net_rim_amms.cod)...等等[rapc] 解决...等等[rapc] 优化[rapc] Utilities.java:449:警告!:局部变量{已完成}初始化但未用于:com.cobi.library.Utilities.split(String,String)...等等[rapc] 填充[rapc] 调用:jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.jarcod MyApp-1.cod MyApp-2.cod MyApp.csl MyApp.cso -CC:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .[rapc] 添加了清单[rapc] 添加:MyApp.cod(in = 63208) (out= 41042)(放气35%)[rapc] 添加:MyApp-1.cod(in = 75448) (out= 42559)(deflate 43%)[rapc] 添加:MyApp.csl(in = 91) (out= 69)(放气 24%)[rapc] 添加:MyApp.cso(in = 157) (out= 93)(放气40%)...等 - 添加我可以在 JAR 中看到的所有文件...[rapc] 添加:MyApp-1.codjava.util.zip.ZipException:重复条目:MyApp-1.cod[rapc] 在 java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175)[rapc] 在 java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)[rapc] 在 sun.tools.jar.Main.addFile(Main.java:713)[rapc] 在 sun.tools.jar.Main.create(Main.java:466)[rapc] 在 sun.tools.jar.Main.run(Main.java:180)[rapc] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[rapc] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[rapc] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[rapc] 在 java.lang.reflect.Method.invoke(Method.java:597)[rapc] 在 net.rim.tools.compiler.c.e.if(未知来源)[rapc] 在 net.rim.tools.compiler.c.e.a(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.a(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.a(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.compile(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.main(来源不明)[rapc] java.io.IOException: jar 命令失败:jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.cod MyApp-1.cod MyApp-2.cod MyApp.csl MyApp.cso -CC:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .[rapc] 在 net.rim.tools.compiler.Compiler.a(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.a(来源不明)[rapc] at net.rim.tools.I/O 错误:jar 命令失败:jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.cod MyApp-1.cod MyApp-2.cocompiler.Compiler.compile(来源不明)[rapc] 在 net.rim.tools.compiler.Compiler.main(来源不明)[rapc] d MyApp.csl MyApp.cso -C C:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .构建失败C:\development\ant\new_test\MyApp\build.xml:65:Java 返回:-1在 org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)在 ca.slashdev.bb.tasks.RapcTask.executeRapc(RapcTask.java:583)在 ca.slashdev.bb.tasks.RapcTask.execute(RapcTask.java:401)在 org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)在 sun.reflect.GeneratedMethodAccessor4.invoke(未知来源)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)在 java.lang.reflect.Method.invoke(Method.java:597)在 org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)在 org.apache.tools.ant.Task.perform(Task.java:348)在 org.apache.tools.ant.Target.execute(Target.java:390)在 org.apache.tools.ant.Target.performTasks(Target.java:411)在 org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)在 org.apache.tools.ant.Project.executeTarget(Project.java:1368)在 org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)在 org.apache.tools.ant.Project.executeTargets(Project.java:1251)在 org.apache.tools.ant.Main.runBuild(Main.java:809)在 org.apache.tools.ant.Main.startAnt(Main.java:217)在 org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)在 org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)总时间:9秒C:\development\ant\new_test\MyApp>

<小时>

解决方法

Esaj 有一个 下面的好答案 在进行编译之前在源代码上运行 Ant replace 任务.这意味着无需在任何生成的 JAR 文件上运行 jarjar 来解决命名空间问题.

这对我有用,因为我有 SDK 源代码.它不适用于我的客户,因为我以 JAR 格式分发我的 SDK.所以我仍然希望得到这个问题的答案.

<小时>

相关

是 [ 如何使用 Ant Build 将 JAR 文件转换为 COD 文件 ] 但该问题尚未得到解答,我已添加更多细节.

不是重复:

解决方案

用一些细节回答我自己的问题...

不得多次调用 rapc - 它会创建太多 COD 文件.这就是我收到该错误的原因.

根据 Michael 的回答,正确的方法是使用普通的 Java 工具构建最终的 JAR 文件(javac & jar) 以及 RIM 的 preverify 命令.

仅在最后一步使用 rapc - 将该 JAR 文件转换为 COD.

处理这个问题的完整 ANT 构建框架太大了,无法放在这里,但下面列出了创建它所需的步骤.每个步骤都可以在此站点上轻松研究(或使用一些谷歌).每一步都非常简单,可以单独调试.

步骤:

  1. javac 用于创建 CLASS 文件的 SDK
  2. 预验证 CLASS 文件
  3. jar SDK
  4. 将 SDK JAR 文件复制到项目中
  5. javac 项目 - 使用 SDK JAR 作为 classpath
  6. preverify 项目 CLASS 文件(再次使用 classpath 中的 SDK JAR)
  7. jar 项目 - 添加 SDK JAR 作为 zipfileset
  8. jarjar 这个项目的 JAR 根据需要重构包名
  9. 最后,在这个 JAR 上运行 rapc - 它不会发现重复的 COD 文件 &应该运行良好.

注意:只需在 SDK 上使用 rapc 即可组合步骤 1-3(如果您需要在 SDK 代码上运行预处理器标记,则需要使用该代码).

通过将其分解为这样的简单步骤,我了解了普通的 Java 工具如何链接到 RIM 的工具链(通常,当您在源文件夹中简单地调用 rapc 时,这一切都是隐藏的).

当然,您仍然需要使用 sigtool 对 COD 进行签名.

我在 ANT 中完成所有这些工作.我使用不同的文件夹来存储每个步骤的输出.通过这种方式,我最终得到了 5 个临时文件夹,但这样可以轻松调试这些步骤.

<小时>

我现在终于明白为什么很少有人能够为我的各种 BB ANT 构建脚本问题提供确凿的答案.这个过程很费力,很长,很难解释.

完成此任务的完整 ANT 构建框架可以跨越许多不同的文件(在我的情况下,我想我现在使用 8 个,包括属性文件).并且它需要良好的 ANT、普通 Java 构建工具和 RIM 的 rapc 命令的工作知识.

我想我已经在我的问题中很好地记录了流程的每个步骤,并在此过程中得到了一些很好的答案.有关更多详细信息,请查看其他问题 &答案.每个都包含有用的链接,以及来自该社区其他开发者的一些很好的见解

How do I use Ant (bb-ant-tools) to compile a JAR file into a COD? i.e. with no other source files


Reason

Ultimately, I need a script that is going to run Jar Jar Links (jarjar) during the build, to get around the namespace issues of using our sdk in multiple apps. Jarjar takes a JAR file as input, and I presume it outputs a JAR file.

So to run jarjar in a bb-ant-tools build, I need to know how to compile that output JAR into a COD.

I am focusing on just this part of the issue to minimise other possible sources of error. I will attempt the jarjar step once I can master building a JAR into a COD.

Progress

1) I can build my project into a working COD, sign and run on device.

2) To include the sdk code, I currently add the source folders to the main project build. (In the future I would like to know how to include the library into the build as a JAR - BlackBerry - Ant script to include JAR in project without external dependancies)

3) Output of this step includes the usual files:

  • MyApp.cod (if I sign this, it runs perfectly on device)
  • MyApp.csl
  • MyApp.cso
  • MyApp.debug
  • MyApp.jad
  • MyApp.jar (I want to run jarjar on this)
  • MyApp.rapc

4) I tried to run a 2nd build, taking the above JAR file and using it as the only source file in the rapc call. I do this by pointing the src tag of rapc at a folder containing only my JAR file.

In the final part of the build, when rapc is adding the files, I get the error:

 java.util.zip.ZipException: duplicate entry: MyApp-1.cod

(full details of error below in edited build output)

I can see that this is the 2nd time that rapc tries to add this file. I do not understand why, since there is only one copy of that file in the JAR.


Build Output (edited with ...etc to make it readable )

build:
    [mkdir] Skipping C:\development\ant\new_test\MyApp\build because it already exists.
     [copy] Copying 1 file to C:\development\ant\new_test\MyApp\build
     [copy] Copying C:\development\ant\new_test\MyApp\icon.png to C:\development\ant\new_test\MyApp\build\icon.png
     [rapc] Compiling 1 source files to MyApp.cod
     [rapc] Executing 'C:\Java\jdk1.6.0_24\jre\bin\java.exe' with arguments:
     [rapc] '-classpath'
     [rapc] 'C:\Java\jdk1.6.0_24\lib\tools.jar;C:\development\tools\bb-jde\jde5.0\components\bin\rapc.jar'
     [rapc] 'net.rim.tools.compiler.Compiler'
     [rapc] '-verbose'
     [rapc] 'import=C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar'
     [rapc] 'codename=MyApp'
     [rapc] 'MyApp.rapc'
     [rapc] '@sources.txt'
     [rapc]
     [rapc] The ' characters around the executable and arguments are
     [rapc] not part of the command.
     [rapc] Setting environment variable: PATH=........etc
     [rapc] Reading resource: MyApp.cod
...etc
     [rapc] Parsing classfile: com/MyApp/ui/views/WelcomeBar.class
...etc
     [rapc] Parsing import: C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar(net_rim_amms.cod)
...etc
     [rapc] Resolving
...etc
     [rapc] Optimizing
     [rapc] Utilities.java:449: Warning!: local variable(s) { finished } initialized but not used in: com.cobi.library.Utilities.split(String,String)
...etc
     [rapc] Populating
     [rapc] Invoking: jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.cod MyApp-1.cod MyApp-2.cod MyApp.csl MyApp.cso -C C:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .
     [rapc] added manifest
     [rapc] adding: MyApp.cod(in = 63208) (out= 41042)(deflated 35%)
     [rapc] adding: MyApp-1.cod(in = 75448) (out= 42559)(deflated 43%)
     [rapc] adding: MyApp.csl(in = 91) (out= 69)(deflated 24%)
     [rapc] adding: MyApp.cso(in = 157) (out= 93)(deflated 40%)
...etc - adding all files I can see in the JAR...

     [rapc] adding: MyApp-1.cod

     java.util.zip.ZipException: duplicate entry: MyApp-1.cod
     [rapc]     at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175)
     [rapc]     at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)
     [rapc]     at sun.tools.jar.Main.addFile(Main.java:713)
     [rapc]     at sun.tools.jar.Main.create(Main.java:466)
     [rapc]     at sun.tools.jar.Main.run(Main.java:180)
     [rapc]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [rapc]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [rapc]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [rapc]     at java.lang.reflect.Method.invoke(Method.java:597)
     [rapc]     at net.rim.tools.compiler.c.e.if(Unknown Source)
     [rapc]     at net.rim.tools.compiler.c.e.a(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.a(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.a(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.compile(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.main(Unknown Source)

     [rapc] java.io.IOException: jar command failed: jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.cod MyApp-1.cod MyApp-2.cod MyApp.csl MyApp.cso -C C:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .
     [rapc]     at net.rim.tools.compiler.Compiler.a(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.a(Unknown Source)
     [rapc]     at net.rim.tools.I/O Error: jar command failed: jar -cfmv C:\development\ant\new_test\MyApp\build\MyApp.jar C:\Users\Richard\AppData\Local\Temp\rapc_598c0c5a.dir\META-INF\MANIFEST.MF MyApp.cod MyApp-1.cod MyApp-2.cocompiler.Compiler.compile(Unknown Source)
     [rapc]     at net.rim.tools.compiler.Compiler.main(Unknown Source)
     [rapc] d MyApp.csl MyApp.cso -C C:\Users\Richard\AppData\Local\Temp\rapc_598c2ad7.dir .

BUILD FAILED
C:\development\ant\new_test\MyApp\build.xml:65: Java returned: -1
        at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)
        at ca.slashdev.bb.tasks.RapcTask.executeRapc(RapcTask.java:583)
        at ca.slashdev.bb.tasks.RapcTask.execute(RapcTask.java:401)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        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:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 9 seconds

C:\development\ant\new_test\MyApp>


Workaround

Esaj has a good answer below that runs the Ant replace task on the source code before doing the compile. This means that there is no need to run jarjar on any resulting JAR file to solve the namespace problems.

This will work for me, as I have the SDK source code. It will not work for my clients, because I distribute my SDK in JAR format. So I'm still hoping for an answer to this question as it stands.


Related

This is a duplicate of [ How to convert JAR FILE to COD file using Ant Build ] but that question has not been answered, and I have added more detail.

This is not a duplicate of:

解决方案

To answer my own question with some details...

One must not call rapc multiple times - it will create too many COD files. That is why I was getting that error.

Following up from Michael's answer, the correct way to proceed is to build the final JAR file using the normal java tools (javac & jar) as well as RIM's preverify command.

Only use rapc for the last step - converting that JAR file into a COD.

A full ANT build framework to deal with this problem is too big to place here, but the steps needed to create it are listed below. Each of the steps can be easily researched on this site (or with some google). Each step is very simple, and can be debugged individually.

Steps:

  1. javac the SDK to create CLASS files
  2. preverify the CLASS files
  3. jar the SDK
  4. Copy the SDK JAR file into the project
  5. javac the project - use the SDK JAR as the classpath
  6. preverify the project CLASS files (again, use the SDK JAR in the classpath)
  7. jar the project - add the SDK JAR as a zipfileset
  8. jarjar this project JAR to refactor package names as required
  9. Finally, run rapc on this JAR - it will find no duplicate COD files & should run fine.

Note: Steps 1-3 can be combined by just using rapc on the SDK (which is needed if you need to run preprocessor tags on the SDK code).

By breaking it down into simple steps like this, I learnt how the normal java tools link into RIM's toolchain (normally this is all hidden when you simply invoke rapc on a source folder).

Of course, you still need to sign the COD with the sigtool.

I do all of this in ANT. I use a different folder to store the output from each step as I go. This way I end up with 5 temp folders at the end, but it made it easy to debug the steps as I go.


I finally understand now why so few people were able to offer conclusive answers to my various BB ANT build script questions. The process is laborious and very long, and hard to explain.

A full ANT build framework to accomplish this can stretch over many different files (in my case I think I'm now using 8 including property files). And it requires a good working knowledge of ANT, normal java build tools, and RIM's rapc command.

I think I have documented each step of the process quite well in my questions about this, and picked up some great answers along the line. For more details, have a look at those other questions & answers. Each one contains useful links, and some good insight from the other developers in this community

这篇关于BlackBerry:在 Ant 脚本中从 JAR 源文件创建 COD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆