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

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

问题描述

我如何使用Ant( BB-ANT-工具)为编译JAR文件成COD ?即没有其他源文件

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

最后,我需要的是要运行瓶瓶链接(jarjar)的脚本的构建过程中,避开在多个应用程序使用我们的SDK的命名空间的问题。 Jarjar需要一个JAR文件作为输入,我presume它输出的JAR文件。

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.

所以要在运行jarjar一个BB-Ant的工具构建,我需要知道的如何编译输出JAR成COD

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

我专注于这个问题,以尽量减少错误的其他可能来源的只是一部分。我会尝试jarjar一步,一旦我能掌握建立一个JAR成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.

1)我可以建立我的项目到工作的COD,标志和设备上运行。

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

2)包含SDK code,我目前的源文件夹添加到主项目构建。 (在未来,我想知道如何将库到构建一个JAR - <一个href=\"http://stackoverflow.com/questions/10582450/blackberry-ant-script-to-include-jar-in-project-without-external-dependancies\">BlackBerry - Ant脚本,包括在项目JAR没有外部的依赖关系的)

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)这一步的输出包括普通文件:

3) Output of this step includes the usual files:


  • MyApp.cod(如果我签这个,它完美地运行在设备上)

  • MyApp.csl

  • MyApp.cso

  • MyApp.debug

  • MyApp.jad

  • MyApp.jar (我想在这个运行jarjar)

  • MyApp.rapc

  • 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)我试图运行第2个版本,采取上述JAR文件,并使用其作为 RAPC 调用的唯一源文件。我通过在包含只有我的JAR文件的文件夹指向的 RAPC 的src 标签做到这一点。

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.

在构建的最后一部分,当RAPC是添加中的文件,我得到的错误:

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

(下文中编辑生成输出误差的全部细节)

我可以看到,这是在第二次是RAPC尝试添加该文件。我不明白为什么,因为在这个JAR该文件的一个副本。

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:
    [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>


解决方法

Esaj 下面很好的答案运行Ant的上的源$ C ​​$ C替换任务做编译之前。这意味着,没有必要对任何可能产生的JAR文件运行 jarjar 来解决问题的空间。


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.

这会为我工作,因为我有SDK源$ C ​​$ C。它不会为我的客户工作,因为我在JAR格式分发我的SDK。所以我仍然希望回答这个问题,因为它的立场。

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.

是重复的[<一个href=\"http://stackoverflow.com/questions/5241872/how-to-convert-jar-file-to-cod-file-using-ant-build\">How使用Ant构建],但这个问题一直没有得到答复,我已经增加了更多的细节,JAR文件转换为COD文件。

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.

这是不会的复制:


  • [<一个href=\"http://stackoverflow.com/questions/3094043/convert-a-jar-file-into-a-cod-file-using-bb-ant\">Convert一个.jar文件到使用BB-蚂蚁] .cod文件 - 我已经使用了公认的答案,而我的错误是不同

  • [<一个href=\"http://stackoverflow.com/questions/10582450/blackberry-ant-script-to-include-jar-in-project-without-external-dependancies\">BlackBerry - Ant脚本包括没有外部的依赖关系]项目JAR - 这个问题是有关将库作为一个JAR,而不是使用源$ C ​​$ C正如我上面做的。在某种程度上,这是一个precursor步骤,作为其输出仍然需要通过jarjar运行。

  • [ Convert a .jar file into a .cod file using bb-ant ] - I have used the accepted answer, and my error is different.
  • [ BlackBerry - Ant script to include JAR in project without external dependancies ] - this question is about adding the library in as a JAR instead of using the source code as I do above. In a way, it is a precursor step, as its output would still need to be run through jarjar.

推荐答案

要回答我的问题有一些细节...

To answer my own question with some details...

一个不能调用 RAPC 多次 - 它会创建过多COD文件。这就是为什么我得到这个错误。

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

的回答跟进,进行正确的方法是使用普通的Java工具来建立最终的JAR文件(javac的&安培; JAR)。以及RIM的 preverify 命令

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.

仅使用 RAPC 最后一步 - 该JAR文件转换成COD

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

一个完整的ANT构建框架来处理这个问题太大,放在这里,而是创造它所需要的步骤如下。每个步骤都可以在这个网站(或与一些谷歌)很容易调查。每个步骤是非常简单的,并且可以单独进行调试。

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.

步骤


  1. 的javac 的SDK创建CLASS文件

  2. preverify 的类文件

  3. JAR 的SDK

  4. 的SDK JAR文件复制到项目

  5. 的javac 项目 - 使用SDK JAR作为的的classpath

  6. preverify Project类文件(再次,请使用SDK JAR中的的classpath 的)

  7. JAR 项目 - 添加SDK JAR作为的 zipfileset

  8. jarjar 这个项目JAR重构包名的要求

  9. 最后,运行 RAPC 这个JAR - 它会发现没有重复的COD文件和放大器;应该运行正常。

  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.

注意:步骤1-3可以只使用 RAPC 的SDK(这是必要,如果你需要运行$ P组合在SDK code $ pprocessor标签)。

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).

通过分解成这样简单的步骤,我学到了普通的Java工具是如何链接到RIM的工具链(通常这是所有隐藏的,当你简单地调用 RAPC 上一个源文件夹)。

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).

当然,你仍然需要与签署的COD sigtool

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

我做的这一切在ANT。我用不同的文件夹到输出存储从每一步,我去。这样,我结束了在最后5临时文件夹,但它使人们容易,因为我去调试步骤。

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.

我现在终于明白为什么这么少的人能提供确凿的答案,我的各种BB Ant构建脚本的问题。这个过程是艰苦和很长,很难解释。

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.

一个完整的ANT构建框架来实现这一点可以跨越多个不同的文件(在我的情况,我认为现在我使用的8包括物业文件)。它需要ANT的一个良好的工作知识,普通的Java构建工具,和RIM的 RAPC 命令。

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

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

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