/ blog / java / string-dumper.html

Root Beer Logo Root Beer

Chris Nokleberg's Fizzy Weblog

February 2005
Su M Tu W Th F Sa
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 18 19
20 23 24 25 26
27 28
Previous  |  Next  |  More...
#  Dumping strings literals

Another feature of Jar Jar Links is the ability to print all of the string literals used by your code. In a way this is similar to the Unix strings(1) command, but jarjar actually parses jars and class files, looking through all the bytecode for each and every string:

java -jar jarjar.jar --strings <classpath>

Here's the first few lines of running the command on the jarjar classes themselves:

	56: "Bad magic number"
	88: "Unknown constant pool tag "
	108: "cannot find index "
	108: " in "
	45: "user.dir"
	50: "path.separator"
	112: ".jar"
	114: ".zip"
	129: "Do not know how to handle "
	175: ".class"

As you can see, if the processed classes include debug information, line numbers will be printed as well.

I added this mostly because when using jarjar to embed other jar files (the main feature) it is important to check if there are any string literals which did not get transformed properly. If not, and they are used for something important like resource loading or reflection, you may have problems using the repackaged jar. Most common cases are handled automatically, but it is better to be safe than sorry.

I suppose this could also come in handy when localizing your code, to make sure that there aren't any stray untranslated strings hidden away in your code.

[Powered By FreeMarker]  [Valid Atom 1.0]  [Weblog Commenting by]