Setting up the Debugger's Apply Code Changes CommandTo be able to use the debugger's Apply Code Changes feature in a free-form project, you need to write a special Ant target for the command and then map that target in the project's project.xml file. The Ant target needs to call the IDE's custom nbjpdareload task, which the IDE uses to reload the fixed code into the debugged program's JVM. See Fixing Code During a Debugging Session in Chapter 7 for information on using the Apply Code Changes command. Creating the debug-fix TargetFollowing is a sample target for running the Apply Code Changes command: <target name="debug-fix" description="Reload Fixed Code Into the Debugger"> <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true"> <classpath ref/> <include name="${selected-file}.java"/> </javac> <nbjpdareload> <fileset dir="${classes.dir}"> <include name="${selected-file}.class"/> </fileset> </nbjpdareload> </target> In this example, the selected-file property picks up the file that you have selected in the IDE. The value of selected-file is passed from the project.xml file when you choose the Run | Apply Code Changes command. The example uses the refid attribute to reference the javac.classpath path element, which needs to be defined elsewhere in your build script. For example, javac.classpath could be defined as in the following snippet: <path > <pathelement location="libs"> </path> Mapping the debug-fix Target to the IDE Command
The mapping might look something like the following example: <action name="debug.fix"> <target>debug-fix</target> <context> <property>selected-file</property> <folder>${src.dir}</folder> <pattern>\.java$</pattern> <format>relative-path-noext</format> <arity> <one-file-only/> </arity> </context> </action> |