0

I'm trying to write a utility to cut down on some of the common errors I have when working with source managed java code that is compiled into a jar file. Errors such as forgetting to add a file to a repository or forgetting to commit the changes to a modified file (after all it works locally) One of the stumbling blocks I have is trying to determine which .java files were used to produce the class files in the jar file. Is this information stored somewhere? The only solution I've been able to come up with is to get a list of the .class files from the jar file (jar -tf), ignore all class files with a '$' in the name, replace the '.class' portion of the string with '.java', and finally, add the appropriate prefix to the path to locate the .java files used to generate the .jar I'm wondering if there is a better way. Thanks

Xaq
  • 558
  • 1
  • 4
  • 13

1 Answers1

0

I am not sure if I could understand well the need of generating Java files names from class files.

I can think of three solutions:

  1. Simplest way is to keep java files as part of jar files. This can be performed using any Build tool or even eclipse.
  2. The way you already have been doing (list and then rename)
  3. Write a utility where you list each class file in the jar file. Then using Java reflection API find out the classes.
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121
  • If I was writing a debugger, I'd should be able to load the executable being debugged and then display the source for it. I basically want to make sure any sources used to generate the jar are in the repository (I didn't forget an svn add) – Xaq Jun 18 '13 at 14:10