Friday, January 25, 2013

Compiling & Running jEdit 5 in NetBeans 7.3

These instructions are obsolete, please visit the updated instructions located here: 
http://www.areaofthoughts.com/2015/02/compiling-running-jedit-5-in-netbeans-80.html

I will show you how to setup the jEdit 5 source code as a NetBeans 7.3 project so you can compile it and do whatever you like with it.
  1. Download the jEdit source code from the jEdit website.
  2. Download the jsr305-2.0.1.jar file from the Maven Repository and place it in a handy folder. Later you will need to add this to the project to resolve dependencies against javax.annotation.Nonnull and javax.annotation.Nullable.
  3. Create a new project folder called jEditProject or whatever name you would like to call it.
  4. Extract the jEdit files from the archive that you downloaded into the new project directory you created in step 3. You can use 7-Zip to decompress it. The folder structure will look similar to this:
jEdit 5 Source Folder Structure






  1. Run NetBeans and choose File >> New Project. Then under Categories, choose Java. Under Projects choose Java Project with Existing Sources.See the following image:
NetBeans 7.3 New Project Dialog Box

  1. Click the Next button and in the next dialog box, set the Project Name and Project Folder. The project folder is the new folder you created in step 3. You may name the project whatever you like, but in this case I named it the same as the project folder. See the following image:
NetBeans 7.3 New Project With Existing Source: Name and Location Dialog Box
  1. Click the Next button and in the next dialog box, you will specify where the existing source files are for your new project. Just click the Add Folder button and choose the jEdit folder that you extracted from the downloaded archive in step 4. See the following image:
NetBeans 7.3 New Project With Existing Source: Existing Sources Dialog Box
  1. Click the Next button and in the next dialog box, choose the files to include and exclude from the project. By default NetBeans chooses all folders and files in the source directory. For now, just leave it at default. Later, you will want to exclude folders that have files that are missing dependencies and are not necessary to be included in the project, you can do that after NetBeans scans the project and tags the files with error badges—warning of the missing dependencies.
  2. Click the Next button and the new project will now show in the Project Window. Now add the jsr305-2.0.1.jar dependency: Right click on the project name and choose Properties. Then choose Libraries on the Categories tree. On the Compile tab, add a Compile-time Library by clicking the Add Jar/Folder button. Navigate to where you placed the jsr305-2.0.1.jar file and add it. See the following image:
NetBeans 7.3 Project Properties: Libraries Tab
  1. Click the OK button. NetBeans will scan the project to resolve dependencies. After NetBeans is done scanning, you will see red error badges appear on some of the packages. These are the packages that can be exclude from the project. See the following image:
NetBeans 7.3 Main Window (Click image for lager size)
  1. Next, right click on the project name and choose Properties, then click the Includes/Excludes button. In the Excludes field, type the folders names that correspond to the packages that need to be excluded from the project. See the following image:
NetBeans 7.3 Configure Includes & Excludes Dialog Box
  1. If you like, you may exclude all the files in the root of the source files folder so they will not show in the Project Window. See the following image:
NetBeans 7.3 Configure Includes & Excludes Dialog Box
  1. Click the OK button. At this point all the unwanted files and packages are removed from the project and their should be no red error badges showing in the Project Window.
  2. Now you will need to let NetBeans know the working folder or jEdit will not be able to find the resources it is looking for. By default the project folder is the working folder, but all the jEdit resources are in the source folder. Right click on the project name in the Project Window and choose Properties. Next, choose Run on the Categories tree. In the Working Directory field, type the path to the source folder or click the Browse button and navigate to it. See the following image:
NetBeans 7.3 Project Properties: Run Dialog
  1. In the above image, the Main Class is not auto-populated and you may either choose it now or choose it when you attempt to run the project for the first time. In either case you will see the same Browse Main Classes dialog box with several project classes with main methods listed. You will need to set org.gjt.sp.jedit.jEdit as your main class. See the following image:
NetBeans 7.3 Browse Main Classes Dialog Box
  1. Now you should be able to compile and run jEdit in NetBeans. You should see the jEdit application window similar to the one shown in the following image:
jEdit 5 Application Window

Note: This works for JDK 6 or JDK 7.

Update 04/13/2013: You may set up JEdit as a Java Free-Form Project in NetBeans where the existing build.xml is used by NetBeans (Ant), but at the time of this writing there is a bug in Ant v1.8.4 - v1.9.0 that prevents the build from occurring in NetBeans. See https://issues.apache.org/bugzilla/show_bug.cgi?id=54641

5 comments:

  1. Hi Mark!

    Many thanks! That was super simple thanks to your great explainations!

    ReplyDelete
  2. Well. I did almost everything as explained :)
    When I try to run from inside NetBeans it opens the installed aplication and not the one that was build.
    Then I double click the jar file in the dist directory and it said my installation is broken and that I need to install the keymaps.
    I copy the keymaps directory from the installed program to the dist directory.
    When I double click now the jar file I get the spash screen but nothing else.
    Well just one last push, I think :)
    Thanks.

    ReplyDelete
    Replies
    1. It is better to set it up as a free-form project and run the included build.xml. Afterwards, add the newly downloaded library directories to resolve any red badges. For the help menu to work right you have to run the Ant target "docs-html". Note that I can only get this to work in NetBeans 7.4 running JDK 8 because of a bug in JDK 7. Running the included build.xml and any of it's targets work fine from the command line. To get a jar fie that works through NetBeans is another issue if it is not set up as a free-form project, but I never saw the keymap issue unless the project working directory was not set right.

      Delete
  3. Thanks for this post.
    It didn't run (but did build) because of an error on the keymaps but that's ok for me. I need it for a school assignment and do not need to run te application.

    ReplyDelete