Newbie: Source files location from jar

A

ankur.sanghi

Hi,

I am a complete newbie here (worked for all my life in Mainframes/
Unix). I want to locate the actual source files for one of the
applications I am currently working on.


All I know from the logs is the location of the jar files. Is it
possible to figure out where the source could be located by looking
at
the jar files? OR


Is there some other way to backtrack where the source files are?


Obviously, this is all arising from poor documentation about the
system...


Please help.


Regards,
Ankur
 
O

Oliver Wong

Hi,

I am a complete newbie here (worked for all my life in Mainframes/
Unix). I want to locate the actual source files for one of the
applications I am currently working on.


All I know from the logs is the location of the jar files. Is it
possible to figure out where the source could be located by looking
at
the jar files? OR

In general, no.
Is there some other way to backtrack where the source files are?


Obviously, this is all arising from poor documentation about the
system...

You said you were "working on" the application whose source you
desire. By "working on", do you mean you are (one of) the programmer(s) of
that application? If so, then wouldn't whatever text editor you were using
to edit the source code have some sort of "history" function to show you
where you might have saved the source?

Otherwise, if you are not a programmer of the application, do you even
have any reason to believe you would have access to the source code in the
first place? I.e. did the programmers actually give you the source code at
some point, or might they have merely given you the application, keeping
the source code as their internal trade secrets or intellectual property?

- Oliver
 
C

Chris Uppal

Is there some other way to backtrack where the source files are?

If you are working without any information at all, then the best you can do
(and it is not guaranteed to be reliable) is to find the names of some of the
classes in the JAR file, and then look for corresponding source file names in
your source directories or code repository.

To extract classnames from a JAR file do:

jar -tf whatever.jar

or (the same, but with more information about each file in the JAR):

jar -tvf whatever.jar

Ignore everything which doesn't end with ".class". Also ignore anything which
has a '$' in the filename. Discard everything up to and including the final
'/' in each name, and replace the trailing 'class' with '.java'. That
/should/ give you the names of the source files -- then you have to go looking
for them.

Obviously there are potential problems with that. One is that the source may
no longer be available; another is that you may find more than one source file
with the same name. More unlikely, whatever build system was used to create
the JAR may have renamed or otherwise changed things so that this technique
doesn't work -- but that's the exception rather than the rule.

Good luck !

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top