Setting up the Debugger s Apply Code Changes Command


Setting up the Debugger's Apply Code Changes Command

To 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 Target

Following 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

  1. In the Files window, expand the project's folder, expand the nbproject folder, and then open the project.xml file.

  2. Within the <ide-actions> element, add a mapping for the Apply Code Changes 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>




NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net