How to Work with JEdit in the NetBeans IDE

June

In this tutorial, you will convert JEdit to a NetBeans project or use the provided JEdit NetBeans project to run, debug, and profile JEdit in the NetBeans IDE.

Introduction

jEdit is a mature programmer's text editor, with a variety of features, which are highly configurable, customizable, and easy-to-use. It is released as free software with full source code, provided under the terms of the GNU General Public License.

The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications.

In this tutorial, you learn how to convert the popular JEdit project into a NetBeans project to develop, debug, and profile the JEdit within the NetBeans IDE.
In the Exercises section, you will use the preconfigured JEdit NetBeans project and perform run, debug, and profile actions. In the Appendix section, you can find detailed steps for creating a JEdit NetBeans project from scratch.

For more information about NetBeans IDE's features and supported technologies, see features.

For more information on how to work with the NetBeans IDE, see the Support and Docs page.

Software needed

Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0.
Since NetBeans 6.0 is under development now, use NetBeans IDE 6.0 Preview (M9) available from NetBeans IDE 6.0 Preview (M9) Download or check the latest working version.

You can also use NetBeans 5.5.1 release available from NetBeans IDE 5.5.1 Download. Don't forget to install the NetBeans Profiler 5.5.1 available from NetBeans Profiler 5.5.1 Download, because it is not part of the NetBeans 5.5.1 IDE download.
For details, see the Using NetBeans 5.5.1 section.

Notations used in this documentation

  • <NETBEANS_HOME> - the NetBeans IDE installation directory
  • <USER_HOME> - the user's home directory. Example: "C:\Documents and Settings\user_home"
  • <jedit_root> - the directory into which the JEdit sources are downloaded

Exercises

Converting JEdit into a Netbeans Project

To download the JEdit source files:

1. Go to and download the JEdit source's archive file from the File Releases section. In this case it is jedit42source.tar.gz.

2. Exctract the archive file (in our case, the file name is jedit42source.tar.gz) into the <jedit_root> directory.

After the JEdit archive file is extracted under <jedit_root>, you will see a subdirectory, in our case called JEdit. For example, on Windows, extracting the JEdit archive file in the root of drive C:\tmp\ creates the following path: C:\tmp\JEdit. On Solaris/Linux, extracting the JEdit archive file in the /home/username directory creates the /home/username/JEdit path.

To create the JEdit Netbeans project:

1. Download the attached nbproject.zip(info) file, and extract it into the <jedit_root> directory. Now you see <nbproject> directory and build-nb.xml file under the <jedit_root> directory.
For more details on how the JEdit NetBeans project has been created see Appendix.

2. Start the NetBeans IDE.

Note: To build JEdit, the IDE uses JDK 1.5. If you install NetBeans with JDK 1.6, change the IDE configuration to use JDK 1.5. To do that, open the netbeans.conf file in the <NETBEANS_HOME>/etc/ directory and change the JDK location to point to JDK 1.5:

# Default location of JDK, can be overridden by using --jdkhome <dir>:
netbeans_jdkhome="C:\Program Files\Java\jdk1.5.0_11"

Then, start the IDE.

3. In the IDE, choose Open Project from the main menu and open the JEdit project from your <jedit_root> directory.

Now you see the JEdit free-form project in the Projects window.

Running JEdit

To run the JEdit application, do the following:

1. In the Projects window, right-click the JEdit node, and choose Run from the pop-up menu.

The IDE will compile the JEdit source and run JEdit.

Note: Expect to see some warnings in the Output window while compiling JEdit. This is a normal behavior.

For detailed tips on how the Run action has been made for JEdit, see the Appendix section.

Debugging JEdit

1. Open the jEdit.java class from the org.gjt.sp.jedit package and set a breakpoint at line 83.

Hint: To find jEdit.java quickly, use the Quick Search NetBeans feature:
In the Projects window, select the org.gjt.sp.jedit package node and type 'jed'.
The IDE will search nodes under the org.gjt.sp.jedit package and find the jEdit.java.

2. Right-click the JEdit project node and choose Debug Project from the pop-up menu.

The IDE opens the Debugger windows and runs JEdit in the debugger until the breakpoint is reached. You can perform Step Into, Step Over, and other debugging activities.
To finish debugging, close the running JEdit application or press the Finish button in the toolbar:

For detailed tips on how the Debug action has been made for JEdit see the Appendix section.

Profiling JEdit using the Netbeans Profiler

1. In the Projects window, right-click the JEdit project node and choose Profile Project from the pop-up menu.

2. In the Profile JEdit window, accept the default "CPU > Analyze Performance" option and click Run.

3. In the Select Task for Profiling window, select the profile task from the checkbox, and click OK.

The Profiler tab opens in the Netbeans IDE.

4. On the Profiler tab, click VM Telemetry to view memory (heap) changes, threads, loaded classes, and other data. Try to perform a few activities on your running JEdit, and notice how the size of the memory heap changes.

5. To finish profiling, press the Stop button under Controls on the Profiler tab. Alternatively, close the running JEdit application.

For detailed tips on how the Profile action has been made for JEdit, see the Appendix section.


Using NetBeans 5.5.1

If you use NetBeans 5.5.1, don't forget to install NetBeans Profiler 5.5.1 separately.

There is only one difference in the steps required to create the JEdit NetBeans project with NetBeans 5.5.1. When following the steps described in the Appendix, skip step 6 in the Creating the JEdit Netbeans project section. NetBeans 5.5.1 does not support the Include/Exclude functionality. Thus, you will see all directories under the JEdit project node in the Projects window.
You can also use the preconfigured project for Netbeans 5.5.1: nbproject551.zip(info).


Appendix

This section describes how to create a NetBeans Project for JEdit from the scratch.

After downloading the JEdit source and extracting it into <jedit_root> (see the Converting JEdit into a Netbeans Project section for details), do the following:

Creating the JEdit NetBeans project

1. Create build-nb.xml file under the <jedit_root> directory, containing the following:

<?xml version="1.0" encoding="UTF-8"?>
<project name="JEdit">
<import file="./build.xml"/>
</project>

This step is required because we do not want to change the original JEdit structure, and we do not want to change JEdit's build.xml file.
For adding extra Ant targets for the JEdit NetBeans project (which are not in the JEdit's build.xml, like run, debug, etc.). So we created a new file, build-nb.xml, under the <jedit_root> directory and will define the extra Ant tasks in this file. For details, see the Adding extra actions for the JEdit NetBeans project section.

2. From the main menu, choose File > New Project.
The New Project wizard opens.

3. In the Categories list, select "General", select "Java Project with existing ANT Script" in the Projects list, and click Next.

4. At the Name and Location page, specify the locations of JEdit's project files and the build-nb.xml file. In our case, JEdit project files are at C:\work\jEdit.

Click Next.

5. At the Build and Run Actions page, the IDE sets the following Ant targets in the fields listed below:

  • Build Project - compile
  • Clean Project - clean
  • Generate Javadoc - javadoc
  • Run Project - empty
  • Test Project - empty

Click Next.

6. At the Source Package Folders page of the wizard, specify <jedit_root> as the source package folder.

Click Next.

7. Click the Includes/Exludes button and specify the following values in the fields listed below:

  • Includes - bsh/**, com/**, gnu/**, installer/**, org/**
  • Excludes - org/gjt/sp/jedit/Java14.java, org/gjt/sp/jedit/print/BufferPrinter1_4.java

This step is required because we do not need to see all directories with the JEdit source. Examine the compile Ant task in the JEdit's build.xml to ensure that all the directories mentioned above are important.

8. At the Java Sources Classpath page, add the <jedit_root> directory to the Java Sources Classpath list.

Click Finish.

JEdit's project node appears in the Projects window.

9. In the Projects window, right-click the JEdit project node and select Properties.
In the Project Properties window, select Output in the Categories list and add the <jedit_root> directory to the output list.

This step is required for the debugging action, which we will add in the next section.

In the next step, we will add run, debug, and profile actions to the JEdit NetBeans project.

Adding extra actions for the JEdit NetBeans project

Standard NetBeans project actions are build, clean, generate javadoc, run, and test. You set some of these actions while creating the JEdit NetBeans project in step 4 (see Creating the JEdit NetBeans project). Here you will learn how to add run, debug, and profile actions to the JEdit NetBeans project.

1. Open the build-nb.xml file in the Editor window of the NetBeans IDE.

Adding the Run action to the JEdit project

To add the Run action to the JEdit project, you need to modify the build-nb.xml file and add Run action to the project's contextual menu.

1. Add the run Ant task to the build-nb.xml:

...
    <target name="run" depends="compile">
        <java classname="org.gjt.sp.jedit.jEdit" classpath="../" dir="../" fork="true"/>
    </target>
    <target name="compile">
        <ant antfile="build.xml" target="compile" dir=".."/>
    </target>
...

This run task runs the JEdit application. A dependency is added here because you must compile code before running it. The next section shows how to implicitly use this run task in the debug and profile tasks. To find out which class is the main class, review the JEdit code or JEdit's build.xml file.

2. In the Projects window, right-click the JEdit project node and choose Properties.
In the Project Properties window, select Build and Run in the Categories list and set the Run Project combobox value to run.

You can view build-nb.xml nbproject.zip(info) file.

Adding the Debug action to the JEdit project

To add the Debug action to the JEdit project, you need to modify the build-nb.xml file and add Debug action to the project's contextual menu.

1. Add the debug Ant task to the build-nb.xml:

...
    <target name="debug" depends="compile">
        <path id="cp" location="../" />
        <nbjpdastart addressproperty="jpda.address" name="JEdit" transport="dt_socket">
            <classpath refid="cp"/>
        </nbjpdastart>
        <java classname="org.gjt.sp.jedit.jEdit" classpathref="cp" fork="true" dir="../">
            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
        </java>
    </target>
...

To define the debug task for this project, you need to specify the NetBeans specific task for debugging (<nbjpdastart>) and then run this task (which was done in the previous section) with the mandatory arguments for JVM that were specified in part of build-nb.xml pasted above.

For more information on how to add a debug project action, see Advanced Free-Form Project Configuration tutorial.

2. In the Projects window, right-click the JEdit project node and choose Properties.
In the Project Properties window, select Build and Run in the Categories list.
Click Add button to add custom contextual menu item, and set the following values in the fields listed below:

  • Label - Debug
  • Ant Target - debug

You can find build-nb.xml in the attached nbproject.zip(info) file.

Adding the Profile action to the JEdit project

To add the Profile action to the JEdit project, do the following:

1. Add the profile Ant task to the build-nb.xml:

...
    <target name="profile" depends="compile">
        <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
        <path id="cp" location="../" />
        <nbprofiledirect>
            <classpath refid="cp"/>
        </nbprofiledirect>
        <java classname="org.gjt.sp.jedit.jEdit" fork="true" logError="yes" dir=".." classpathref="cp">
            <classpath refid="cp"/>
            <jvmarg value="${profiler.info.jvmargs.agent}"/>
        </java>
    </target>
...

To define the profile task for this project, specify a NetBeans-specific task for profiling (<nbprofiledirect>) and then run this task (which was done in the previous section) with the mandatory argument for JVM that were specified in part of build-nb.xml pasted above.

For more information on how to add the profile action, see tutorial.

We do not need to add Profiler contextual menu item because NetBeans Projects already has it.

Explore build-nb.xml in the attached nbproject.zip(info) file.


Summary

In this tutorial, you learned how to start JEdit development in the NetBeans IDE. You have completed the following exercises:
  • Convert JEdit to a Netbeans Project.
  • Run, debug, and profile the JEdit Project.
You also read tips on how to convert an existing project into a NetBeans project by using a JEdit project as an example.

See Also

References:

Attachments

add-debug-action.jpg Info on add-debug-action.jpg 36148 bytes
breakpoint.jpg Info on breakpoint.jpg 70414 bytes
build-nb-create.jpg Info on build-nb-create.jpg 34124 bytes
debug-action.JPG Info on debug-action.JPG 36148 bytes
debug-action.jpg Info on debug-action.jpg 13339 bytes
file-type.jpg Info on file-type.jpg 51182 bytes
jedit-nbproject.jpg Info on jedit-nbproject.jpg 23282 bytes
open-nbproject.jpg Info on open-nbproject.jpg 33154 bytes
profile-action.jpg Info on profile-action.jpg 13666 bytes
profile-jedit.jpg Info on profile-jedit.jpg 84631 bytes
profiler-task.jpg Info on profiler-task.jpg 18267 bytes
profiler-window.jpg Info on profiler-window.jpg 36680 bytes
project-actions-compile.jpg Info on project-actions-compile.jpg 39115 bytes
project-actions-dist.jpg Info on project-actions-dist.jpg 39046 bytes
project-classpath-includes.jpg Info on project-classpath-includes.jpg 55899 bytes
project-classpath.jpg Info on project-classpath.jpg 42935 bytes
project-existing-ant.jpg Info on project-existing-ant.jpg 47703 bytes
project-output.jpg Info on project-output.jpg 36007 bytes
project-source-includes.jpg Info on project-source-includes.jpg 53151 bytes
project-source.jpg Info on project-source.jpg 51645 bytes
quick-search.jpg Info on quick-search.jpg 30438 bytes
run-action.jpg Info on run-action.jpg 33978 bytes
run-jedit.jpg Info on run-jedit.jpg 21534 bytes
runing-jedit.jpg Info on runing-jedit.jpg 51830 bytes
stop-debug.jpg Info on stop-debug.jpg 3899 bytes

NetBeans