tags:

views:

49

answers:

2

Hello.

I created a Java library with an ant file to build it into a JAR. When I use this JAR file from another Java project, the method parameter names appear as in Eclipse method hint/autocomplete: arg0, arg1, arg...

for instance, the method:

     void publishStatus(String jobId, int count);

appears as:

     void publishStatus(String arg0, int arg1);

What am I missing?

Thanks,

Edit

Looks like this has already been discussed in much more detail here: http://stackoverflow.com/questions/939194/preserving-parameter-argument-names-in-compiled-java-classes

+2  A: 

You need to have the java compiler include "debug information" when compiling the classes, and recreate your jar file.

For ant this means having a debug="true" attribute on the <javac ...> tag.

Thorbjørn Ravn Andersen
thanks. Looks like this works for classes only, not interfaces.
wsb3383
+1  A: 

Java method argument names are not represented in the class file format. The relevant parts of the JVM spec are sections 4.3.3 and 4.6. (Strictly, they can be in some cases, but they cannot be included for interfaces, and won't be included unless the relevant compiler options were set when the class was compiled.)

In practice, Eclipse can also present you with method argument names if it can find and parse the source code corresponding to the class files. In the simple case, you can address this by downloading a ZIP file etc containing the relevant source code, and attaching it to the binary JAR.

FOLLOWUP re your comment:

I wasn't meaning to include the source folder in the JAR (though that obviously works). If you look at the Eclipse properties for a dependent JAR file, there's a way to attach the corresponding source JAR or directory. (I cannot run Eclipse right now to give you precise details.) Anyway, this approach doesn't require you to recompile or otherwise change the dependent JAR.

Stephen C
I noticed there has been much discussion on this here: http://stackoverflow.com/questions/939194/preserving-parameter-argument-names-in-compiled-java-classes
wsb3383
...and Thanks! this works, I included the source folder in the JAR, I can now see all names in both classes and interfaces :)
wsb3383