Debugging Java.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 07 Feb 2012 16:51:31 +0200
changeset 1215 84101bddf00c
parent 1214 fe28cec0bb40
child 1216 7a3ade740d3f
Debugging Java.
java.rst
--- a/java.rst	Tue Feb 07 16:43:11 2012 +0200
+++ b/java.rst	Tue Feb 07 16:51:31 2012 +0200
@@ -147,10 +147,30 @@
   $ jar cmf myManifestFile myFile.jar *.class
   $ jar -cfe Main.jar foo.Main foo/Main.class
 
-Profiling java.
+Profiling Java.
 ===============
 ::
 
   $ java -Xprof com.vendor.product.Clazz
   $ java -Xrunhprof:help
 
+Debugging Java.
+===============
+
+Compile with ``-g`` to preserve source code information::
+
+  $ javac -g -cp $CLASSPATH -sourcepath $SRC_DIR -d $BUILD_DIR
+
+To run Java program in debugger::
+
+  $ jdb -cp $CLASSPATH -sourcepath $SRC_DIR
+
+To attach to Java application you firstly must run application with::
+
+  $ java -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=$PORT \
+    com.vendor.product.Clazz
+
+and then attach with debugger::
+
+  $ jdb -attach $PORT
+