CompileProtege4InEclipseOneProject
From Protege Wiki
Compile and run the Protege-OWL editor (4.0 alpha) from a Generic IDE
To follow are instructions for compiling and running the 4.0 alpha version of the Protege-OWL editor from a generic IDE environment. We use the Eclipse development environment as our example IDE to show how this is done. The approach taken in this documentation is to take the entire protege owl editor project and load it as a single project in eclipse.
Please note that:
- These instructions are only valid for the 4.0 alpha version of Protege. If you want to compile and run the 3.x versions of Protege, we have separate instructions available elsewhere.
- This is only one of several possible ways of compiling and running Protege 4 from Eclipse. This particular page is not meant to be exhaustive.
Contents |
Checking out the project
Before starting it is very convenient to turn off auto-building of projects. I recommend this because the project takes several steps to get properly set up and the automatic build is not useful. It is important to remember to turn automatic building back on later (the appropriate moment will be noted in this document). To turn off automatic building make sure that the "Build Automatically" item is unchecked in the Eclipse project menu.
If you have not done so already go to instructions for doing so on our Wiki and follow the instructions to setup subversion in eclipse. Then go to the SVN Repository Exploring perspective and navigate to protege4/protege-standalone/trunk.
Right-click on the trunk folder and choose Checkout... In the resulting "Checkout from SVN" dialog, leave all of the default settings (as shown below) and click Finish.
In the "New Project" dialog, choose Java Project and click Next.
In the "Create a Java Project", choose a name for the project. We are not yet ready to configure the source and class path, so just click finish to finish the dialog.
At this point eclipse may ask if you want to switch to the java perspective (the answer is yes) and to "confirm overwrite" (the answer is "OK"). Now you wait a while while eclipse downloads the protege 4 sources. If you did not turn off auto-building of projects then the build that follows the download will fail so it is ok to abort it.
Configuring the project
Setting up an ant build script
Now we will configure the sources, class paths and build directories for the project. The first step is to configure and run an ant build. While this may not be intuitive to many IDE developers, it turns out that this will save the developer a noticeable effort that would otherwise be needed to set up a run configuration.
This will create and initialize the build directories for the project. It will also create a working distribution of the Protege 4 OWL editor which is also useful. We will do this with the "External tools" button. This is near the upper left hand side of the screen.
If you click the right hand part of this button (the downward pointing arrow) you will see some choices. Select and click on "External Tools".
As a result of making this selection you will see the "External Tools" dialog. In this dialog select "Ant Build" and click on the "New" button in the upper left hand side of the dialog.
Now you will see a dialog for creating, managing and running ant configurations. In the main panel give the configuration a memorable name (e.g. "Ant Build").
Now browse for the buildfile and select the build.xml file in the owleditor project.
Next go to the "Targets" tab and make sure that the default target ("run") is deselected and that the desired target ("equinox") is selected.
Save this by clicking "Apply" and then run the script by clicking on "Run". After the ant script finishes running refresh the project by right clicking on the project and then clicking on "Refresh".
At this point we have achieved two things. First we have created a working Protege 4 distribution in the directory owleditor/build/dist/equinox. This distribution contains a double-clickable run.bat for windows users and a double-clickable run.command for Mac users. Also for unix users there is the run.sh shell script.
Second we have created the directories for the "*.class" files that eclipse is going to build. Using these directories has several advantages as we will show.
In addition there will be occasions (not too frequent) when the ant build script will be needed to refresh the project.
Setting up the Build Path
Now we have everything we need in place to configure the project. What we need to do is to configure the "Build path". To do this right click on the project and select "Properties".
A dialog will come up. In that dialog select "Build Properties" and then select the "Sources" tab.
Now we will first delete the invalid information in the "Sources" tab.
We then add the real sources. Click on "Add folder..." and a dialog box will come up to choose the sources. Expand the plugins tree, expand each plugin and then select the src directory for each plugin. The only exception to this is the org.semanticweb.owl.owlapi which is a pure library.
Set the "Default output folder" to "owleditor/build/classes".
At this point you have a workable build path. Now optionally users may choose to set the build file the same way that it is set for the ant builds. The advantage of this approach is that ant and eclipse generate built .class files in the same place. This means that when an ant script is run it will execute quickly because the .class files have already been built by eclipse. If you choose to do this, click on "Allow output folders for source folders" and configure the output folders and shown below.
Continue this process for each of the projects. If the subdirectories of the classes directory are not visible as shown in the figure above, then it is possible that you forgot to refresh the project after the ant build step.
Finally set the "Default output folder" to something else such as "owleditor/build/eclipse.classes".
At this point, regardless of whether you did the optional class configuration, you need to configure the libraries for the project. Go to the "Libraries" tab of the "Java Build Path" configuration, click on add jars and add all the jars in the lib directories under the plugins directory.
You will also need to add the three jars in the osgi/equinox folder. When all the jar files are added the configuration should look like this.
Click ok to finish the build path configuration. You can turn on autobuilding and let the project build.
Running Protege 4
A simple way to run protege 4 at this point is to make an ant runnable as described in the ant build script page but using the run target instead of the build target. Actually you can abbreviate the steps by simply copying the existing ant runnable and change its name and target. When we describe how to build a plugin we will provide a different method of providing a runnable which will be preferable for plugin development.





















