Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

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

1 min read

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?



Our software libraries allow you to

Convert PDF to HTML in Java
Convert PDF Forms to HTML5 in Java
Convert PDF Documents to an image in Java
Work with PDF Documents in Java
Read and Write AVIF, HEIC, WEBP and other image formats
Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.