The classpath setting in JSwat is simply the classpath setting for the debuggee. If you are launching the debuggee from within JSwat, then the classpath must be set in the Launch dialog. If the debuggee was launched outside of JSwat and you are connecting the debugger to it, then the classpath has already been set.
The sourcepath is like the classpath but rather than pointing to compiled classes, it points to source files. The sourcepath is used to locate the source code for a class or method whenever a locatable event occurs in the debuggee. If a sourcepath is not set, JSwat will use the classpath to find the source files, assuming that the source code and classes are stored in the same directory tree.
The sourcepath is defined in the Session Settings dialog, activated via the Settings item in the Session menu.
The sourcepath has the same structure as the classpath, except it
refers to the location of source code, rather than the location of
class files. Thus, if you have a classpath that looks like
/home/me/java/build
, which contains .class
files such as org/mine/Widget.class
, and your source code
is similarly located in a directory such as
/home/me/project/src
, which contains .java
files such as org/mine/Widget.java
, then the sourcepath
would be set to /home/me/project/src
. Note that the
sourcepath can contain directories as well as archives, such as
.jar
and .zip
files.
For users of Microsoft Windows, the following example may be easier
to translate to your own environment. Say you have a classpath that
looks like C:\java\project\build
, which contains
.class
files such as org\mine\Widget.class
,
and your source code is similarly located in a directory such as
C:\java\project\src
, which contains .java
files such as org\mine\Widget.java
, then the sourcepath
would be set to C:\java\project\src
.
JSwat uses both the classpath and sourcepath to locate source
files, checking the sourcepath before the classpath. The names of
source files are determined from the class or method in which a
locatable event occurred within the debuggee. In most cases, the
bytecode contains a source file name attribute (and sometimes even a
leading path), which allows the debugger to easily locate the source
files. Otherwise, the debugger must guess at the name of the source
file, assuming that the filename extension is .java
and
the name of the file will be the same as the name of the class (e.g.
Foobar.java
for Foobar
class).
Because JSwat considers the package name of the class to imply the
path that leads to the source file, it will first attempt to convert
the package name into a file path. For example, the class name
java.lang.String
would become the path and file
java/lang/String.java
. If JSwat does not find the source
file, then it will ignore the package name and simply look for a file
with the appropriate name at the root of each source path (e.g.
String.java
).
Whenever a locatable event occurs, JSwat attempts to locate and display the source code for that location. This occurs whenever a breakpoint is hit, and while single-stepping through code. If this does not appear to work, check the Troubleshooting section below.
If it seems that JSwat is not able to locate your source code and display it, then there are a few steps you can take to resolve the issue.
First, did you set the sourcepath in the Session Settings dialog? Open that dialog and look for the Sources section of the settings. Make sure it points to the root of your source tree, as explained above.
Second, is your source code written in the Java language? If not,
then the filename extension is probably not .java
, in
which case you need to modify the Source Extension
setting in the Options dialog (found in the
Tools menu).
A tool for getting more information about the class you are
debugging and its source-related attributes is the source
command. Open the Commands view via the
Window menu and type in source
name.of.class where name.of.class
is the
fully-qualified name of the class for which JSwat is unable to locate
the source code. The output of this command will display the value of
the source file attribute from the class bytecode, as well as the
leading "source paths", if any. These source paths are not to be
confused with the JSwat sourcepath setting, as they pertain to this
particular class only. However, this information can be used to
understand how the sourcepath setting should be set. For instance,
with the java.lang.String
class, the "source paths" value
is java/lang/String.java
which indicates that the
sourcepath setting should include the directory which contains the
java
directory of the source code tree. In this case,
however, it is actually the src.zip
file that should be
entered into the sourcepath setting.
By the way, the source code for the JDK core classes is discovered and automatically added to the sourcepath setting. For more information on how to manage this, see the Runtime Manager dialog.