Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Add debug info

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Add debug info

    Hi everyone,

    I have a question that I would be grateful if anyone helped me.
    I hope that I'm posting it at the right place in the forum.

    I need to add debug information to a JAR file. Adding debug info to a .java file is with the usage of *javac -g filename.java* but I don't know how to do the same task for a JAR file.

    I have searched a bit but couldn't find anything useful.
    Could anyone guide me please?

    Regards


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    975
    Thanks
    7
    Thanked 205 Times in 181 Posts

    Default Re: Add debug info

    A jar file is a sort of archive file. (In fact its a zip file, and will open and be readable by any software that reads zip files.) So adding debug information to a jar file really involves adding that information to some (or all) of the class files that the jar archive contains.

    So, the procedure is first recompile all of the code with javac -g, then recreate the jar archive using the new class files.

    I can forsee a couple of possible difficulties. The first is that you don't have the original source files from the compiled form of which the jar archive was originally created. The other is that compiling the source and/or recreating the archive (with all its other resources) might be a rather complex and undocumented process. In either case you should apply to the jar archive's author.

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    Thanks a lot for your reply.

    Quote Originally Posted by pbrockway2 View Post
    So, the procedure is first recompile all of the code with javac -g, then recreate the jar archive using the new class files.
    Before that I need to decompile all the class files then use the -g option. Is that correct?
    I have jd-gui that some times gives errors. Do you know a better decomiler? (I remember searching a while ago that somehow all the decompilers have errors)


    Quote Originally Posted by pbrockway2 View Post
    I can forsee a couple of possible difficulties. The first is that you don't have the original source files from the compiled form of which the jar archive was originally created. The other is that compiling the source and/or recreating the archive (with all its other resources) might be a rather complex and undocumented process. In either case you should apply to the jar archive's author.
    The jar file that I need its info is jasper-runtime-5.5.23.jar, does this make the process easier or not?

    Thanks in advance.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    975
    Thanks
    7
    Thanked 205 Times in 181 Posts

    Default Re: Add debug info

    Personally I would not attempt to decompile code of any size - not unless it was really, really important. And that's why I said if you don't have the source to person to ask about that is the author.

    There's the legality to consider, but also my experience (even with my own code, of very modest size, and containing nothing tricky) is that decompilers produce code that you have to go through and fix before it will compile. So use whatever decompiler you want, but realise that you may have a lot of work to do before you are able to compile -g.

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    For all the files in the related folder how can I use the -g option? Or maybe the option can only be used for a single file?

    At the moment I have problem with one of the classes (although I might have problems with others in future) what do you suggest, should I work on this class for now?

    Regards

  6. #6
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Add debug info

    ill second the decompiling...ive decompiled a few programs and there has always been missing code

  7. #7
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    Quote Originally Posted by pbrockway2 View Post
    The other is that compiling the source and/or recreating the archive (with all its other resources) might be a rather complex and undocumented process. In either case you should apply to the jar archive's author.
    I have found the source from Tomcat's site.

    Is there any easy way to use the -g option for all the files not just a single one?
    Could you please guide me?

    Thanks in advance.

  8. #8
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    975
    Thanks
    7
    Thanked 205 Times in 181 Posts

    Default Re: Add debug info

    Is there any easy way to use the -g option for all the files not just a single one?
    You add the -g flag to get the debugging stuff. The rest of the command is exactly as it would be without the flag.

    Depending on how familiar you are with compiling from the command line you may wish to consult the javac man page.

  9. #9
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    Is there any way to get sure that the debug info is added?

  10. #10
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    975
    Thanks
    7
    Thanked 205 Times in 181 Posts

    Default Re: Add debug info

    javap -l

  11. #11
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    Quote Originally Posted by pbrockway2 View Post
    I did not know exactly which option would help me therefore I tried some of them.
    For example the output for option -l is:

    Compiled from "ProtectedFunctionMapper.java"
    public final class org.apache.jasper.runtime.ProtectedFunctionMapper {
    public static org.apache.jasper.runtime.ProtectedFunctionMapper getInstance();

    LineNumberTable:
    line 64: 0
    LocalVariableTable:
    Start Length Slot Name Signature

    public void mapFunction(java.lang.String, java.lang.Class, java.lang.String, java.lang.Class[]);
    LineNumberTable:
    line 91: 0
    LocalVariableTable:
    Start Length Slot Name Signature
    0 10 0 this Lorg/apache/jasper/runtime/ProtectedFunctionMapper;

    public static org.apache.jasper.runtime.ProtectedFunctionMapper getMapForFunction(java.lang.String, java.lang.Class, java.lang.String, java.lang.Class[]);
    LineNumberTable:
    line 133: 0
    LocalVariableTable:
    Start Length Slot Name Signature

    public java.lang.reflect.Method resolveFunction(java.lang.String, java.lang.String);
    LineNumberTable:
    line 182: 0
    LocalVariableTable:
    Start Length Slot Name Signature
    0 10 0 this Lorg/apache/jasper/runtime/ProtectedFunctionMapper;
    }


    I think that there is no debug info added, Am I right?

    Regards

  12. #12
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    975
    Thanks
    7
    Thanked 205 Times in 181 Posts

    Default Re: Add debug info

    That output is showing both the line number table and the local variable table. So it appears the code was compiled -g:lines,vars

  13. #13
    Junior Member
    Join Date
    Jun 2013
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Add debug info

    Thanks a lot @pbrockway2 for all your help.

Similar Threads

  1. question about debug mode
    By leonne in forum Java IDEs
    Replies: 5
    Last Post: May 15th, 2013, 07:18 AM
  2. question about debug mode
    By leonne in forum Java Theory & Questions
    Replies: 2
    Last Post: January 9th, 2013, 04:16 PM
  3. How can I debug this code?
    By chenom in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 16th, 2012, 12:36 PM
  4. Pls help me to debug this code
    By coen1604 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2011, 10:00 AM
  5. can someone help me debug plzz
    By andys in forum Object Oriented Programming
    Replies: 1
    Last Post: November 27th, 2010, 05:37 PM

Tags for this Thread