Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Newbie: Source files location from jar

Thread view: 
ankur.sanghi@gmail.com - 06 Mar 2007 17:28 GMT
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
Oliver Wong - 06 Mar 2007 19:06 GMT
> Hi,
>
[quoted text clipped - 6 lines]
> 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
Chris Uppal - 06 Mar 2007 19:56 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.