# HG changeset patch # User Oleksandr Gavenko # Date 1328626291 -7200 # Node ID 84101bddf00c100bbce0fb09049ac1c2504b527f # Parent fe28cec0bb40ee195010bbb3d03ae6107b826137 Debugging Java. diff -r fe28cec0bb40 -r 84101bddf00c 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 +