Changing package names before building in Bamboo
Asked Answered
U

2

6

I recently discovered that BlackBerry treats all classes with the same fully-qualified name as identical--regardless of whether they are in entirely different apps or not--causing apps that use different versions of our shared libraries to break when they are installed on the same phone.

To solve this problem, we are planning on changing the package names to include a version number, then building. Can someone explain how, using Bamboo, I can insert a step in our build process that:

  • changes certain packages names
  • replaces all code references to the old package name with references to the new package name?
Unplaced answered 28/2, 2011 at 19:5 Comment(0)
E
2

A great tool that is made especially for the task of changing the fully qualified names of Java classes in jar files is jarjar. It can be used easily from within Ant, or alternatively from a shell script.

I have never used Bamboo - I assume, it should work there, too. Of course, there may be some special restrictions in that environment (concerning bytecode manipulation), I don't know about (?)

Exudation answered 4/3, 2011 at 21:10 Comment(2)
Drat, that looks really cool, and I'm not sure it will work in our specific case. It looks like jarjar replaces the jar task, but we are not using jar to build--BlackBerry has its own ant task, rapc, that handles compilation. Do you know if it's possible to use jarjar to just do the package renaming step?Unplaced
@Amanda: I did a quick google search for rapc (I really know nothing about it). It looks, as if it can be used with jar files, too: codeforfun.wordpress.com/2008/09/09/… "The last parameter should specify either a jar file containing the compiled classes or be a list of the .java files you intend to compile." If that works, you could first jar your classes, then apply jarjar, and then run rapc on the jar.Exudation
W
2

I'm not familiar with Bamboo and you did not include much information about your build system. If you are using maven, you could use the shade plugin:

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

The second example here shows how to configure package renaming. The resulting jar file would then have to be processed by rapc as in Chris Lerchers comment to his answer. It should be possible to also integrate this in a maven build using the exec plugin.

Wahl answered 10/3, 2011 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.