Skip to content
ghxiao edited this page Sep 29, 2014 · 10 revisions

This page is DEPRECATED. Please check How to Use Eclipse, How to Use Ontop as Maven Dependency and How to Debug Protege Plugin instead

Note, the obdalib-protege4 project is NOT a normal Java project. It is a OSGi bundle. As such, the Maven build files, and the Eclipse run configuration are slightly different to traditional projects. The Maven build file for the OBDA Protege 4 plug-in is built using the maven-bundle-plugin. The generated bundle is packed with all needed dependencies required and is ready to be dropped in your Protege-4.0/plugins folder. With respect to Eclipse runtime environment, the Maven files will take care of part of the setup work, however, you will need to complete some parts that the Maven files and the m2eclipse plugin are not able to do automatically.

We also included a obdalib-parent project in which shared dependencies are declared as well as version numbers and package names.

Table of Contents

Setting up the environment with Maven console

These are the instructions to checkout and compile the OBDALib projects (obdalib-core, obdalib-owlapi and obdalib-protege4) using only Maven, for the Eclipse instructions look below in this same page.

Requirements

  • Maven 2 (instruction here)
  • SVN

Installation steps

  1. Checkout the source of the obdalib projects with:
    svn co https://babbage.inf.unibz.it/krdb/obda/obdalib/trunk/obdalib obdalib
    This will download the root project and all the children.
  2. Do a mvn install for the parent project. The output of executing these tasks will be similar to the one shown in the following example:
    ~> cd obdalib/
    obdalib> mvn install
    ...
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] ------------------------------------------------------------------------
    [INFO] obda-parent ........................................... SUCCESS [1.520s]
    [INFO] obdalib-core .......................................... SUCCESS [9.400s]
    [INFO] obdalib-owlapi ........................................ SUCCESS [0.321s]
    [INFO] obdalib-protege4 ...................................... SUCCESS [7.398s]
    [INFO] ------------------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 20 seconds
    [INFO] Finished at: Wed Sep 08 16:25:46 CEST 2010
    [INFO] Final Memory: 42M/249M
    [INFO] ------------------------------------------------------------------------
    

You will have now compiled and packed each of these projects. You will also have installed the resulting JARs into your local Maven repository (normally located at ~/.m2/) and they will be available for other dependent projects. Each of these JARs is also located in the target folder, including the OBDA Plugin's JAR which you can deploy in you Protege 4.0 installation.

Running out of memory. If you get an OutOfMemory error while compiling the obdalib-protege4 project you will need to extend the memory available to Maven's virtual machine. You can do this by defining the following variable in your environment:

MAVEN_OPTS=-Xmx1024m.

In Mac/Linux you can do this appending the following line to your {.profile} or {.bashrc} files

export MAVEN_OPTS=-Xmx1024m
In windows, you can do this in the System environment variables tab.

Setting up the environment with Eclipse

Using these instructions you will be able to a) compile and pack the obdalib, obdalib-owlapi and obdalib-protege4 projects from Eclipse and b) you will be able to run an instance of the OBDA Plugin that allows for Eclipse' hot code replacement a feature that will allow you to easily debug the plugin from eclipse without require you to restart your VM every time you make a change to the code.

Requirements

  • Eclipse 3.5
  • The sublipse plugin for Eclipse for SVN support.
  • The m2Eclipse plugin and the m2extras plugin (located in the same page) for Eclipse for Maven integration.
  • A running Protege 4.0 Eclipse run configuration (

Instructions for the basic setup

  1. Add a settings.xml to your ~/.m2/ folder as follows:

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
    </settings>
    
  1. Define a new repository location https://babbage.inf.unibz.it/krdb/obda/obdalib/
  2. Select the trunk/obdalib folder in the trunk folder and do a checkout as maven project
Now you will have an Eclipse workspace in which you can edit code of these projects and create new JAR distributions of these projects with Maven and launch Protege 4 with the latest version of the plugin for protege. Instructions for these task are below:

To generate jars for the projects inside Eclipse

To create JAR packages of these projects you need to right click on the main pom.xml file, right click on it and select Run as -> Maven install.

Running out of Memory. If you get an Out of Memory error while installing the obdalib-protege4 project you need to increase the memory available to Maven's VM. To do this setup a new Maven run configuration as shown in the figures and you should use that configuration instead of 'Maven install' to create the bundle of the obdalib-protege4 project.

Steps:

  1. Select the pom.xml file in the obdalib project. Right click on it and do 'Run as -> Maven build ...'
  2. In the next screen, set as Goal install
  3. In the JRE tab add the VM argument -Xmx1024m
  4. Click on apply and Run

Now use that run configuration whenever you want to build the OBDA Plugin.

Installation steps for the hot code replacement setup

Now we will setup the protege4-plugin project in Eclipse so that it has a structure that allows for the definition of a Run Configuration for Eclipse that is compatible with Protege 4 plugin architecture and that allow us to use hot code replacement for debugging of our project. In order to do this, we need to setup the obdalib-protege4 project so that it places all classes and resources required to describe the plugin in a single folder. We will achieve this by creating links to the sources of the obdalib, obdalib-owlapi as well as creating a folder that will contain these resources.

  1. Setup Protege 4.0 in your Eclipse workspace. Follow the instructions http://www.cs.man.ac.uk/~iannonel/eclipseSetup/eclipseSetupMain.html and make sure you are able to run Protege 4 from within Eclipse before proceeding. Preferably name the project in your workspace protege4.
  2. Run maven install for the main pom.xml file as explained above. This will generate a .jar file in the obdalib-protege4/target folder, if you don't see it do a refresh in your target folder or verify that the build completed successfully. Afterwards run maven bundle:bundle (you can also add -DskipTests) in the obdalib-protege4 folder. This will add some .jar files to the jar generated before.
  3. Unpack the generated jar file
  4. Create a folder named 'plugin-runtime'
  5. Copy all the contents of the unpacked jar to the 'plugin-runtime' folder except the it org samples folders. You will have copied many jar files, XML files, the META-INF folder, etc.
  6. Right click on the 'plugin-runtime' folder and do 'Build Path -> Use as source folder'
  7. Create linked sources for each source folder of the obdalib subprojects. Follow the instructions bellow.
  8. Open the Build Path of the obdalib-protege4 project, go to the Source tab and make sure that there are no exclusion for the obdalib-protege4/src/main/resources source folder. By default all the files are excluded, i.e., remove this and click ok. Do the same for reformulation-core resources.

We have now a folder, namely target/classes inside the obdalib-protege4 project folder that holds all the classes, jars and resources (MANIFEST.MF etc) that are required to form a functional Protege 4 plugin. We can use this folder to create a Run Configuration for eclipse that allows for 'hot code replacement'. To do this, simply update your Protege 4 run configuration so that it also searches for plugins in the obdalib-protege4/target/classes folder. Do this as follows:

Creating a run/debug configuration

 Once you have setup the workspace and and you see that there are no compilation errors you 
  1. Go to the menu "Debug configurations" dialog.
  2. Duplicate your existing protege4 configuration (the one that you created in step 3 of the guide) using the duplicate item in the contextual menu.
  3. Select the new configuration and rename it to obdalib-protege4.
  4. Go to the Arguments tab in the dialog and replace the current content with:
    -Dosgi.clean=true
    -Dlog4j.configuration=file:log4j.xml
    -Dorg.protege.plugin.extra="${workspace_loc:obdalib-protege4}/target/classes"
    -Xmx2048m
    
  1. Optional. Go to the Source tab, click Add.. and add all the projects in the workspace (this will allow you to easily inspect code).
  2. Click Apply and Run or Debug.

The result of these steps is shown in the following figures:

Now you can start the projects using the shortcut in the debug or run menu using the obdalib-protege4 run configuration you just created.

Creating a linked source folders

You can create the links to the source folders in two ways. Try to use the first way as it will be much faster and less prone to errors.

Option 1

This method used a simple java program to create automatically all the src links using the information from obdalib's pom.xml file. The program and the sources to the program can be located here and here. Tested on Mac and Windows.

Assuming the path to the obdalib folder is /workspace/obdalib (in windows this would be c:/workspace/obdalib)

  • Make sure the obdalib-protege4 project is closed.
  • Download the jar 'Maven Eclipse Source Link creator' from here put it in any temporal folder.
  • Execute the command:
    java -jar mvn-e-lnk.jar /workspace/obdalib/pom.xml /workspace/obdalib/obdalib-protege4
  • Open the project again, now the run configuration you made in one of the previous steps should work.

Option 2

Do this for each obdalib subproject

  • Right click on your main project (quonto-obda-protege4 in this case)
  • Select "Build path -> Link source..."
  • Select the folder obdalib/$subproject/src/main/java (or resources) as location
  • Name the link $subproject-java or $subproject-resources accordingly.
  • Click "Finish"
Clone this wiki locally