This section covers the following topics:
Debugging Java applets in Java Plug-in has not been simple in the past, partly because the applets use many services and facilities from the Java 2 Runtime Environment, Java Plug-in, and the browser itself. If the applet does not work, the developer needs to spend time diagnosing the problem.
The purpose of this document is to simplify the debugging process. It provides techniques and suggestions for developing applets in Java Plug-in and describes some common mistakes in applet development.
In order to debug applets, you must have the appropriate version of the JDK
installed on your machine. Also make sure to compile
your .java
files with -g
option with javac
.
To begin debugging your applet:
-Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_shmem,address= <connection-address>,server=y,suspend=n
The <connection-address> could be any string which is used by the java debugger later to connect to the JVM. For example,
-Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_shmem,address=2502,server=y,suspend=n
See JPDA Connection and Invocation for the details on the possible runtime parameters for debugging.
JDK
<version> in <jdk-path>
" for the Java Runtime
Environment, where <version>
is the Java Plug-in version
and <jdk-path>
is the path to the JDK installation.
For example, "JDK1.4 in C:\jdk1.4
" .
-g
option with javac
.
jdb -attach <connection address>
in a DOS command prompt. <connection address>
is the
name mentioned in the step 1. For example, if <connection address>
is 2502
, you will run the command as
jdb -attach 2502To learn more about the Java Debugger (jdb), see The Java Debugger.
When debugging applets in Java Plug-in, make sure that only one instance of the browser is being used for debugging using the same connection address at the same time. Otherwise, it will result in a conflict, since the Java Runtime for each instance of the browser will try to gain exclusive access to the connection address. To debug applets in both Internet Explorer and Netscape Navigator, run either Internet Explorer or Netscape Navigator with Java Plug-inbut not both at the same time.
Debugging applets in Java Plug-in with Active Desktop is discouraged because an instance of Internet Explorer will always be running in the desktop process during the lifetime of the user session.
You can use other Java 2 debuggers, like Inprise's JBuilder or Symantac's VisualCafe, instead of jdb. To use these debuggers, you will need to change the project option in these IDEs to attach Java Plug-in in the browser process on the same machine or remote machine. Different Java Runtime Parameters may also be required in the Java Plug-in Control Panel. For more information, consult your Java 2 debugger or IDE manuals.
One of the most powerful tools in Java Plug-in is the Java
Plug-in Console. It is a simple console window for redirecting all the System.out
and System.err
messages. The console window is disabled by
default; it can be enabled from the Java Plug-in Control Panel or the task bar.
If the console is enabled, you will see the console window appear when Java
Plug-in is used in the browser.
Similar to the Java Plug-in Console, this is a file that records all the System.out
and System.err
messages. The trace file is disabled by default
but is automatically enabled when the Java Plug-in Console is enabled. The trace
file is normally located in user.dir
, and the file is called .plugin<version>.trace
.
For example, in Windows NT this file is located in C:\WINNT\Profiles\<username>\.plugin<version>.trace.
javaplugin.trace
property This property controls whether Java Plug-in prints its trace messages during
execution. This is useful to applet developers to determine what is occuring
within Java Plug-in. The possible values are true
or false
.
By default this property is false
. To enable this property, set
-Djavaplugin.trace=true
in the Java Runtime Parameters field in
the Advance Panel of the Java Plug-in Control Panel.
java.security.debug
propertyThis property controls whether the security system of the Java 2 Runtime Environment prints its trace messages during execution. This is usful when a security exception is thrown in an applet or when a signed applet is not working. The following options are supported:
access
print all checkPermission
resultsjar
print jar verification informationpolicy
print policy informationscl
print permissions SecureClassLoader
assigns The following options can be used with access
:
stack
include stack tracedomain
dumps all domains in contextfailure
before throwing exception, dump the stack and
domain that didn't have permission For example, to print all checkPermission
results and dump all
domains in context, set -Djava.security.debug=access:stack
in the
Java Runtime Parameters field in the Advanced Panel of the Java Plug-in Control
Panel.
Java Plug-in provides a rich set of documentation to help developers use the various features of Java Plug-in. The documentation includes a FAQ, which includes some of the most frequently asked questions by developers. Make sure you read and understand these documents before applet development, as it may save you hundreds of hours in debugging.
Although Java Plug-in provides the Java 2 Runtime Environment within Internet Explorer and Netscape Navigator, most of the facilities are provided by the Java 2 Runtime itself, rather than by Java Plug-in. Therefore, if a problem occurs in Java Plug-in, it may be either a problem in Java Plug-in, the Java 2 Runtime itself or a user error. It is extremely important to determine where bugs originate, as it will affect the speed of bug evaluation and fixing. Here are some suggestions for isolating bugs:
appletviewer
. Java Plug-in is mainly derived
from appletviewer
and has inherited problems from appletviewer
as well. This step should be performed only if the applet doesn't require
specific browser facilities that Java Plug-in provides, like HTTPS or RSA
signing.appletviewer
, it is likely the problem
is in the Java 2 Runtime Environmentand not in Java Plug-in. appletviewer
,
it could be either a Java Plug-in problem or user error. Please examine the
applet code to see if it makes any assumptions about the execution environment.
For example, in appletviewer
the current directory is set to
the current directory in the shell when appletviewer
is launched,
whereas the current directory in Java Plug-in may be set to the browser's
directory. Therefore, loading resources from the current directory may work
in appletviewer
but not in Java Plug-in.To submit a bug report, go to the Java Development Connection's BugParade. Before submitting a bug, search the BugParade to determine if the bug has already been reported. In some cases, a workaround may also have been suggested. If the bug is not already reported, submit a new bug report to the Java Plug-in team. In the bug report, include the following information:
appletviewer
;To submit a feature request, do so through the Report A Bug or Request a Feature page.In the feature request, please make sure the following information is included:
The purpose of the Java Plug-in Feedback alias, java-plugin-feedback@sun.com, is for customers to provide feedback on product features and the product in general. This alias is not intended for bug report submission. To submit a bug report, please follow the instructions given above.