Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java method parameter names from a JAR file in Eclipse

Tags:

java

eclipse

jar

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: Preserving parameter/argument names in compiled java classes

like image 960
wsb3383 Avatar asked Oct 03 '10 03:10

wsb3383


People also ask

How do you call a method inside a jar?

We can give the method name as parameter. If it is public, it will run. java -jar <Jar name> <Method Name>. It executes all the methods with the same name across all the packages in the jar.


1 Answers

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.

like image 192
Stephen C Avatar answered Oct 05 '22 07:10

Stephen C