Eclipse: Set up project and example extension from git sources

From OpenJUMP Wiki
Jump to navigation Jump to search

Download and install eclipse (if not already available)

Download and unzip from
https://www.eclipse.org/downloads/packages/
either
Package for Enterprise Java and Web Developers
Package for Java Developers
each will do fine for OJ development

All the below was tested with eclipse version 2024.06.

OpenJUMP project

Import into eclipse IDE

NOTE: The file system paths below are for windows but can analogous be some unix/linux/mac paths.

  1. Start the eclipse application
  2. Create and open a new workspace e.g. C:\workspace-OpenJUMP
  3. File > Import...
    1. Git > Projects from Git (with smart import) ; Next>
    2. Clone URI ; Next>
    3. enter URI https://github.com/openjump-gis/openjump.git ; Next>
    4. make sure at least branch main is selected ; Next>
    5. choose a location for the project folder e.g. C:\workspace-OpenJUMP\OpenJUMP ; Next>
    6. eclipse will now clone the git repository into the project folder
  4. Import Projects dialog pops up
    1. Folder OpenJUMP should be preselected Import as Maven
    2. Finish>

eclipse should now build the maven project without errors (warnings can be ignored)

Create run/debug configuration

When the project builds fine you will need to provide some information to be able to run OJ directly from the built project.

  1. Run > Run Configurations...
    1. Right click Java Application on the left side ; Select New Configuration
    2. change Name above tabs from
      New Configuration
      to
      OpenJUMP
    3. tab Main
      1. make sure Project is
        OpenJUMP
      2. add Main Class
        com.vividsolutions.jump.workbench.JUMPWorkbench
    4. tab Arguments
      1. add Program arguments
        -default-plugins scripts\default-plugins.xml -extensions-directory "lib\ext" -extensions-directory "target\lib.ext.core" -extensions-directory "target\lib.ext.plus" -I18n en_US -v info
        NOTE: you can
        change the language/region with the parameter -I18n or
        raise the log verbosity to debug with -v or
        remove -extensions-directory "target\lib.ext.plus" to simulate OJ CORE
      2. add VM arguments
        -Djava.system.class.loader=com.vividsolutions.jump.workbench.plugin.PlugInClassLoader
    5. save configuration with button Apply (bottom right)
    6. run configuration with button Run (bottom right)

eclipse should now start OJ and be able to do so in the future. you can also debug OJ by selecting the created run configuration under Run > Debug Configurations... .
there are also handy buttons on the toolbar available to do so quickly. note the small downward arrows beside them!

HelloWorld extension

OJ extension projects usually are managed/build by maven. Extensions bundle/initialize/install plugins. Here's a quick explanation.

Maven also packages them into self contained distribution jar files that can be placed under 'lib/ext/' in your OJ installation to be used. In case the extension needs additional (not-jar) files the distribution is done as zip file containing jars and files/folder to be placed under 'lib/ext/'.

Strictly speaking a checkout of the complete OJ sources is not needed to develop an extension. It is perfectly possible to do so against an OJ portable distribution. We may document that later in case somebody requests it.

Import project

generally you repeat all steps from Import OJ into eclipse above. but this time use

  1. URI https://github.com/openjump-gis/helloworld-extension.git
  2. Folder name HelloWorld-Extension

let the import finish and build.

Create run/debug configuration

same here. running OJ with the extension included utilizes the basic run/debug configuration created above. we will duplicate it and add some command line parameters for the OJ plugin loader to find and load the extension classes/files during runtime.

simply put - we will remove the folders to look for additional extensions but provide a new one where the extensions classes are compiled to. additionally we use -limit-ext-lookup false to have OJ not only to look into jar files but additionally recurse through all folders and look for extension class files as well.

  1. Run > Run Configurations...
    1. expand Java Application on the left side; Right click OpenJUMP; Select Duplicate
    2. a new configuration OpenJUMP (1) will be created
    3. edit this configuration
    4. change Name above tabs from
      OpenJUMP (1)
      to
      HelloWorld
    5. tab Arguments
      1. change Program arguments to
        -default-plugins scripts\default-plugins.xml -extensions-directory "lib\ext" -I18n en_US -v info -limit-ext-lookup false -extensions-directory ${workspace_loc:helloworld-extension}/target/classes
        NOTE: we removed target/lib.ext.core,plus as the other extensions are not strictly needed to develop an extension, they slow down startup and clutter the interface. you may add those later to test incompatibilities against them later though.
    6. save configuration with button Apply (bottom right)
    7. run configuration with button Run (bottom right)

eclipse should now start OJ and the HelloWorld extension should show up under Plugins > Example.