Update: JPDF2HTM5 has been rebranded as BuildVu and JPDFForms has been rebranded as FormVu

Debugging Java – what is the difference between a ‘debug’ and a non-debug jar?

This blog article was posted in response to a question on our forum about the difference between our debug and non-debug jars.

We you run a Java program in an IDE, you have all the information available, so that if there is an error the IDE can take you to the exact place for the error. Here is an example I have simulated (obviously there are NO bugs in any of my code!).

Java exception

That is great for your code but what about if you are running somebody else’s code as a jar?

It turns out that you can optional include information in the jar which means that Java can still give you useful information such as the line number so that you can identify the line even though you do not have access to the source code. This is an option you can set when you create the class files with the Java compiler (javac). Here is our Ant code to compile our PDF library.


<if>
<equals arg1="${debug_jar}" arg2="true" />
<then>

<property name="build.debuglevel" value="lines,vars,source"/>

<echo>Include debug info level=${build.debuglevel}</echo>

//compile with additional info in the jar
<javac srcdir="${build.dir}/src" nowarn="true" verbose="off" destdir="${bin.dir}" target="${compiler.target}" debug="true"
debuglevel="${build.debuglevel}" source="${compiler.target}">
<classpath>...</classpath>
</javac>
</then>
<else>

//compile with no additional info in the jar
<javac srcdir="${build.dir}/src" nowarn="true" verbose="off" destdir="${bin.dir}" target="${compiler.target}" source="${compiler.target}">
<classpath>...</classpath>
</javac>
</else>

This includes the additional metadata in the jar so that Java can provide more debug info but it makes the jar larger. The jars are identical and the idea is that you can use the debug_jar in place of the full jar for development or debugging and easily swap between. We find this very useful.

Do you have any debug tips for Java?

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>