Setting up the Debug File Command


To be able to debug a selected file in a free-form project in the IDE, you need to write an Ant target for the command and then map that target in the project's project.xml file.

Creating the debug-selected-file Target

Following is a sample target for debugging a selected file:

<target name="debug-selected-file"     depends="compile-selected-files-in-src" if="netbeans.home"     description="Debug a Single File">     <fail unless="selected-file">Must set             property 'selected-file'</fail>     <nbjpdastart name="${selected-file}" addressproperty="jpda.address"             transport="dt_socket">         <classpath ref/>         <sourcepath ref/>     </nbjpdastart>     <java fork="true" classname="${selected-file}">         <jvmarg value="-Xdebug"/>         <jvmarg value="-Xnoagent"/>         <jvmarg value="-Djava.compiler=none"/>         <jvmarg          value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>         <classpath ref/>     </java> </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 Debug File command.

This example also assumes you have a working compile-selected-files-in-src target (like the example in Setting up the Compile File Command earlier in this chapter), although it is also possible to have the target depend on a different compile target you have set in your script.

The example uses the refid attribute to reference two path elements (run.classpath and debug.sourcepath) that need to be defined elsewhere in your build script. For example, run.classpath could be defined as in the following snippet:

<path >     <pathelement path="${javac.classpath}">     <pathelement path="${build.classes.dir}"> </path>


The paths for javac.classpath and build.classes.dir would need to be defined in their own path elements. If the path element needs to reference a physical location, the location attribute could be used to specify a directory relative to the Ant project's base directory. For example:

<path >     <pathelement location="classes"> </path>


Refer to Table 16-3 for a description of the various parts of the target.

Mapping the debug-selected-file 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 Debug File command.

The mapping might look something like the following example:

<action name="debug.single">     <target>debug-selected-file</target>     <context>         <property>selected-file</property>         <folder>${src.dir}</folder>         <pattern>\.java$</pattern>         <format>java-name</format>         <arity>             <one-file-only/>         </arity>     </context> </action>


See Table 16-6 for a description of the parts of the <action> element in the project.xml file. See Handling Properties in the project.xml File earlier in this chapter for information on calling properties from the project.xml file.



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