NetbeansedJEdit

How to Work with JEdit in the NetBeans IDE

By: Daria Titova, with contributions of Aleksandre Iline and Mikhail Vaysman

January 2008

This tutorial shows you how can work with a large existing project in NetBeans IDE. 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.

Contents


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 http://www.netbeans.org/products/ide/features.html.

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.

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 http://downloads.sourceforge.net/jedit 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 a directory.

After the JEdit archive file is extracted, you will see a subdirectory, in our case called JEdit, which is the <jedit_root> directory. 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_NetbeansedJEdit.zip 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.

Image:open-nbproject_NetbeansedJEdit.jpg

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

Image:jedit-nbproject_NetbeansedJEdit.jpg


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.

Image:run-jedit_NetbeansedJEdit.jpg

The IDE will compile the JEdit source and run JEdit.

Image:runing-jedit_NetbeansedJEdit.jpg

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.

Image:breakpoint_NetbeansedJEdit.jpg

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.

Image:quick-search_NetbeansedJEdit.jpg

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

Image:debug-action_NetbeansedJEdit.jpg

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:

Image:stop-debug_NetbeansedJEdit.jpg

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.

Image:profile-action_NetbeansedJEdit.jpg

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

Image:profiler-window_NetbeansedJEdit.jpg

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

Image:profiler-task_NetbeansedJEdit.jpg

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.

Image:profile-jedit_NetbeansedJEdit.jpg

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_NetbeansedJEdit.zip.


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.

Image:project-existing-ant_NetbeansedJEdit.jpg

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

Image:project-actions-compile_NetbeansedJEdit.jpg

Click Next.

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

Image:project-source_NetbeansedJEdit.jpg

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

Image:project-source-includes_NetbeansedJEdit.jpg

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.

Image:project-classpath_NetbeansedJEdit.jpg

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.

Image:project-output_NetbeansedJEdit.jpg

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.

Image:run-action_NetbeansedJEdit.jpg

You can view build-nb.xml nbproject_NetbeansedJEdit.zip 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

Image:add-debug-action_NetbeansedJEdit.jpg

You can find build-nb.xml in the attached nbproject_NetbeansedJEdit.zip 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_NetbeansedJEdit.zip 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:

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo