Compile and Run Core Protege from Eclipse (93A)
To follow is some documentation on how one would go about compiling and running Core Protege from the Eclipse development environment. (96G)
Important notes: (96H)
- There is more than one way to compile and run Core Protege from Eclipse. This page documents one possibility, but is not meant to be exhaustive. (93B)
- These instructions are valid for the 3.x series of Core Protege. They are not applicable to Protege 4.0. (96I)
- If you don't like development environments, we provide an Ant build script called "build.xml" for Core Protege that is located in our Subversion repository: http://smi-protege.stanford.edu/repos/protege/protege-core/trunk/build.xml. (96J)
Quick Links (96K)
- Checkout the source code for Core Protege (94H)
- Configure the Core Protege Project (94I)
- Handle Auto-Generated Code (94J)
- Run Protege (94G)
- Eliminate Warning Messages in the Console (96F)
Checkout the source code for Core Protege (93C)
Launch Eclipse and go to the SVN Repository Exploring perspective. (This step assumes that you have already installed an Eclipse plug-in called Subclipse that adds Subversion integration to the Eclipse IDE). Click the "Add SVN Repository" button to bring up the "Add SVN Repository" dialog. In the "Url" text box, type the following URL: (93F)
http://smi-protege.stanford.edu/repos/protege/ (93G)
... and click Finish. Eclipse should look like the following screenshot at this point: (93H)
Once you have successfully connected to the Protege Subversion repository, navigate to the folder protege-core/trunk and right click to bring up the context menu. Choose the "Checkout..." option to bring up the "Checkout from SVN" dialog. Choose the options indicated in the screenshot below and click Finish. (93J)
In the resulting "New Project" wizard, select "Java Project" and click Next. In the "New Java Project" dialog, type a project name (for this documentation, we will use "protege-core"). In the JRE section of this dialog, it is important to pick a version of Java that Protege supports (as of the writing of this documentation on April 3, 2007, the necessary version of Java is 1.5). Choose the options indicated in the screenshot below and click Next. (93L)
In the "Java Settings" portion of the wizard, change the default output folder to protege-core/classes as indicated in the screenshot below and click Finish. (93N)
At this point, Eclipse will begin checking out the source code for Core Protege. When the process is completed, switch to the Java perspective and Eclipse should look something like the following: (93P)
Configure the Core Protege Project (93R)
Right-click on protege-core in the Package Explorer and choose Properties. In the "Properties for protege-core" dialog, click "Java Build Path" on the left, and click the Libraries tab. On the Libraries tab, click the "Add Jars..." button and select the protege-core/lib folder: (93S)
Select all of the JAR files in the lib directory and click OK. The Libraries tab should now look like the following screenshot: (93U)
Click OK to close the Properties dialog. (93Y)
Handle Auto-Generated Code (93Z)
At this point, you will notice that there are still some errors in the Java perspective that indicate that the source code is not compiling: (93W)
The reason for the compiler errors is that Core Protege uses some auto-generated code that is not housed in the Subversion repository. The code must be generated using an application called JavaCC. After you have installed JavaCC, you can run the following from the command line: (940)
javacc <your-path-to-grammar-file> (941)
Note that the grammar file for Core Protege is called "Parser.jj" and is located in the protege-core/bin directory. To follow is a screenshot of running JavaCC on a Windows machine: (942)
Running JavaCC on Parser.jj will produce seven new Java files. These files must be copied into the following directory of the protege-core source tree: protege-core/src/edu/stanford/smi/protege/storage/clips. (946)
You may need to right-click on the clips directory in the Package Explorer and choose Refresh to make sure that Eclipse detects these new files in the source tree. After adding the new source files, you will see that there are no longer any compile errors: (947)
Run Protege (949)
Now that the Protege source code compiles, we can create a run configuration that will allow us to run Protege from Eclipse. (94A)
Click the small down arrow next to the Run button on the Eclipse toolbar and choose "Run..." to bring up the "Run" dialog. Choose Java Application from the list on the left and click the "New launch configuration" button. In the Name text box, type "protege-core" and fill in the rest of the fields as indicated by the screenshot below: (94B)
Click the Apply button and then click the Close button. When running Protege, it is a good idea to enable the Console view in Eclipse because Protege outputs helpful logging information to the console. To enable the Console view, choose Window -> Show View -> Console. (94D)
To run Protege, click on the small down arrow again next to the Run button and choose the newly created protege-core run configuration. Protege should launch from Eclipse and you should see the following output in the console view: (94E)
Eliminate Warning Messages in the Console (95Z)
In the above screenshot you can see that there are two warning messages displayed when you run Protege. (960)
The first warning: (963)
WARNING: missing bundle: protege_text -- BundleHelper.<init>() (964)
... is displayed because Protege is expecting a particular Java properties file in the directory from where it is executed. To fix this warning, copy the file protege-core/src/edu/stanford/smi/protege/resource/files/protege_text.properties to the root directory of your protege-core Eclipse project. This is the directory from which the Protege executable is launched. (961)
The second warning: (965)
WARNING: Plugins directory not found: C:\eclipse-workspace\protege-core\plugins -- PluginUtilities.findPluginsDirectory() (962)
... is displayed because Protege expects a subdirectory to exist below the execution directory called "plugins". This is the directory that houses all the Protege plug-ins that are loaded when Protege starts up. There are two options for eliminating this warning message: (966)
Option 1: Create an empty directory called "plugins" directly below your protege-core Eclipse project. On a Windows machine, the directory structure would look like this: (967)
Option 2: Alternatively, if you already have an installation of Protege somewhere else and you are interested in having the contents of the plugins subdirectory loaded, you can pass a VM parameter called protege.dir to specify the location of the desired plugins directory. To specify a VM parameter, you need to bring up the Run dialog again, choose the protege-core Java Application, and click the Arguments tab. To follow is a screenshot of specifying the protege.dir VM parameter for the protege-core project: (969)
To follow is a screenshot of Protege's output to the console window after performing the steps above to eliminate warning messages: (96B)
Note that the "missing bundle" warning is no longer present and that Protege loaded the contents of a plugins directory that was specified as a VM parameter. (96D)
It is also helpful to note that Protege prints the version number, build number, and version of Java it is using to the console. This information can be very helpful when trying to debug problems. (96E)
Author: Jennifer Vendetti (96P)