Monday, February 23, 2015

Compiling, Running & Editing jEdit 5 in NetBeans 8.0

I will show you how to setup the jEdit 5 source code as a NetBeans 8.0.2 free-form project so you can compile it and do whatever you like with it.

You should have NetBeans 8.0.2 properly installed along with JDK 1.8.0_31. Apache Ant 1.9.4 is required and is included with NetBeans 8.0.2. You may also use an external installation of Apache Ant 1.9.4 or higher. In this example, we are using an external installation of it. In either case, the path to your Ant installation must be in your system path.
  1. Download the jEdit source code from the jEdit website.
  2. Create a new project folder called "jEditProject " or whatever name you would like to call it.
  3. Extract the jEdit files from the archive that you downloaded into the new project directory you created in step 2. You can use 7-Zip to decompress it. The folder structure will look similar to this:
jEdit 5.2 Source Folder Structure
  1. Run NetBeans and choose File >> New Project. Then under "Categories," choose "Java." Under "Projects" choose "Java Free-Form Project." See the following image:
NetBeans 8.0.2 New Project Dialog Box
  1. Click the Next button and in the next dialog box, set the "Location" to be the folder you extracted from step 2. The other fields will populate automatically. 
NetBeans 8.0.2 New Java Free-Form Project Dialog Box—Name and Location
  1. Click the Next button twice and you will see the "Source Package Folders." Set the Java "Source Level" to JDK 1.7 and the "Encoding" to UTF-8. Click the Finish button. See the following image:
NetBeans 8.0.2 New Java Free-Form Project—Source Package Folders
  1. 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 have members that cannot be resolved until the project build is run and dependencies are downloaded. See the following image:
NetBeans 8.0.2 Projects Window
  1. Next, right click on the project name and choose "Build" and dependencies are downloaded and the project is built.
  2. At this point you will still see error badges on some packages. These can be resolved by adding some of the JARs that were downloaded in step 9, to the project's classpath. You will also need to add "ant.jar" from your Ant installation and "tools.jar" from your JDK installation to the project's classpath. Right click on the project and choose "Properties" and then under "Categories" choose "Java Source Classpath." Add the Jars as shown in the following screenshot:
NetBeans 8.0.2 Project Properteis—Java Source Classpath
  1. There should not be any error badges now. If so, you may need to add more libraries to the classpath.
  2. Now expand the build.xml node in your project and find the target "docs-html." Right click on this node and choose "Run Target." This will build the jEdit help files. See the following screenshot:
NetBeans 8.0.2 Projects Window—Run docs-html Target
  1. There are some packages and files that may be hidden from view. These are the build packages and some java files. Right click on the project and choose "Properties" and under "Categories" choose "Java Sources" and click the "Includes/Excludes..." button. See the following image for the filter pattern to use:
NetBeans 8.0.2 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 8.0.2 Configure Includes & Excludes Dialog Box
  1. To run the project from NetBeans, without having to wait for it to build each time, you can add a new target to Ant by duplicating the existing run target and removing the "depends" attribute. See the following screenshot:
jEdit 5.2.0 build.xml "just-run" Target
  1. You can add a project context menu item for the "just-run" target as well as the "docs-html" target by right clicking on the project and choosing "Properties" and under Categories choose "Build and Run." Then under "Mapping of Custom Contextual Menu Items:" add the 2 entries shown in the following screenshot:  
NetBeans 8.0.2 Project Properties—Build and Run
  1. Now when you right click on the project, there are two new menu items shown. See the following screenshot:
NetBeans 8.0.2—jEdit 5.2.0 Project—New Menu Items
  1. Now you can run jEdit from the new menu item "just-run."
jEdit 5.2.0

No comments:

Post a Comment