Newbie: Source files location from jar

Discussion in 'Java' started by ankur.sanghi@gmail.com, Mar 6, 2007.

  1. Guest

    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
    , Mar 6, 2007
    #1
    1. Advertising

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > 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
    Oliver Wong, Mar 6, 2007
    #2
    1. Advertising

  3. Chris Uppal Guest

    wrote:

    > 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
    Chris Uppal, Mar 6, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric McIntyre

    Jar files in Jar files

    Eric McIntyre, May 24, 2004, in forum: Java
    Replies:
    1
    Views:
    460
    Roedy Green
    May 24, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    551
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,687
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,720
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    637
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page