Using Eclipse

Eclipse is a Java IDE available from eclipse.org.

Creating a new project

To create a new project, we choose from the File menu, File->New->Java Project. This will bring up a dialog like New Eclipse Project 1. Type in a name for this project, like “OESample1”, and then press the “Next” button.

../_images/Eclipse-new-project1.PNG

New Eclipse Project 1

Next, we need to add the OpenEye JAR to our project. Click the “Libraries” tab at the top of the dialog, then choose “Add External JARs...”. Browse to the location where you expanded the distribution you downloaded above and pick the appropriate “oejava-*-jar” for your platform. See New Eclipse Project 2.

../_images/Eclipse-new-project2.PNG

New Eclipse Project 2

You should then see something like: New Eclipse Project 3. Click the “Finish” button.

../_images/Eclipse-new-project3.PNG

New Eclipse Project 3

Adding a class to our project

Next we need to add a Java class to hold our sample code. Click File->New->Class to bring up the “New Class” dialog as in Eclipse New Class.

../_images/Eclipse-New-Class.PNG

Eclipse New Class

There are several things we want to do on this dialog.

  • Choose a package name for this class. For example, “myoechemexamples”.
  • Choose a name for the class: “OESample1”.
  • Remove the default “Superclass” entry, since it is not required.
  • Check the box to add a “main” to our class. And uncheck the box for “Inherits abstract methods”.
  • Then click the “Finish” button.

This will take you back to Eclipse and open the new class in the editor, ready to add code.

Near the top of the file, add the import for oechem.

import openeye.oechem.*;

Then add our sample code inside the main method.

public static void main(String[] args) {
    OEGraphMol mol = new OEGraphMol();
    oechem.OEParseSmiles(mol, "c1ccccc1CCCBr");
    System.out.format("mol has %d atoms\n", mol.NumAtoms());
}

When you are finished, your sample should look something like Editing in Eclipse.

../_images/Eclipse-Editing.PNG

Editing in Eclipse

Running our example inside Eclipse

We can now test run our program in Eclipse. In the toolbar, click the “Run” button as shown in Running in Eclipse.

../_images/Eclipse-Run.PNG

Running our example in Eclipse

This should produce some output in the “Console” window like Console output.

../_images/Eclipse-Console-Output.PNG

Console output from our example.

And now you’ve created your first OEChem Java sample. You can now add code and continue to run inside Eclipse to try out more of the OEChem API.

Creating an executable JAR

At some point, you may want to run your example outside of Eclipse, or you may want to deploy the application to another machine. One easy tool for this is to use the FAT JAR Eclipse plugin downloadable from http://fjep.sourceforge.net/.

Once installed, right click on the OESample1 project icon, in the Eclipse “Package Explorer” and choose “Build Fat Jar”

../_images/Eclipse-FATJAR.PNG

Choose Build Fat Jar.

Then in the next dialog:

  • Pick a name for you new JAR
  • Make sure the name of the class we just created is set as the “Main-Class”.
  • Click “Finish”.
../_images/Eclipse-FATJAR2.PNG

Build Fat Jar.

You should now be able to open a terminal in the location where you saved the JAR file and run it from the command-line.

$> java -jar OESample1_fat.jar
mol has 10 atoms