:orphan:

.. needs to be tested before published 10/25/23

How to Develop with the OpenEye C++ Toolkit in Eclipse
========================================================

Eclipse is an integrated development environment (IDE) available from eclipse.org. It
is one of several IDEs available for C++ development and is used in this guide
because it is free and available on multiple platforms.

The essential step in using Eclipse and other IDEs for OpenEye toolkit development is
to specify the OpenEye toolkit as a resource to use during development.

Download Eclipse for C/C++ Developers from `eclipse.org <https://www.eclipse.org/downloads/packages/release/2023-03/r/eclipse-ide-cc-developers>`_.
URls may change from time to time, so just be sure you download the installer for C/C++
for your operating system.  There are versions for Windows, macOS, and Linux.

After you have installed Eclipse, proceed to create a new project.

Creating a New Project
----------------------

To create a new project, we choose from the File menu, 
File->New->C/C++ Project. This will bring up a dialog like
:ref:`New Eclipse Project 1<figure_eclipse_new_project1>`.
Type in a name for this project, like "OESample1", and then 
press the "Next" button.

.. _figure_eclipse_new_project1:

.. figure:: images/Eclipse-new-project1.PNG
   :align:  center
   
   **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 
:ref:`New Eclipse Project 2<figure_eclipse_new_project2>`.

.. _figure_eclipse_new_project2:

.. figure:: images/Eclipse-new-project2.PNG
   :align:  center
   
   **New Eclipse Project 2**

You should then see something like:
:ref:`New Eclipse Project 3<figure_eclipse_new_project3>`.
Click the "Finish" button.

.. _figure_eclipse_new_project3:

.. figure:: images/Eclipse-new-project3.PNG
   :align:  center
   
   **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 
:ref:`Eclipse New Class<figure_eclipse_new_class>`.

.. _figure_eclipse_new_class:

.. figure:: images/Eclipse-New-Class.PNG
   :align:  center
   
   **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.

.. code-block:: java
   
   import openeye.oechem.*;

Then add our sample code inside the main method.

.. code-block:: java

   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
:ref:`Editing in Eclipse<figure_eclipse_editing>`.


.. _figure_eclipse_editing:

.. figure:: images/Eclipse-Editing.PNG
   :align:  center
   
   **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 
:ref:`Running in Eclipse<figure_eclipse_run>`.

.. _figure_eclipse_run:

.. figure:: images/Eclipse-Run.PNG
   :align:  center
   
   **Running our example in Eclipse**

This should produce some output in the "Console" window like
:ref:`Console output<figure_eclipse_console_output>`.

.. _figure_eclipse_console_output:

.. figure:: images/Eclipse-Console-Output.PNG
   :align:  center
   
   **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. An easy
tool for this purpose is an export option built into modern versions
of Eclipse.

To create a standalone JAR executable, right-click on the project
and select ``Export...``.

.. figure:: images/Eclipse-export-JAR.png
   :align:  center
   
   **Exporting a Runnable JAR**

Then in the next dialog:

   * Pick a name for your and destination for the new JAR
   * Make your choice about how libraries should be packaged.
   * Click "Finish".

.. _figure_eclipse_build_fatjar2:

.. figure:: images/Eclipse-export-JAR-options.png
   :align:  center
   
   **Set Options for the New 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.

.. code-block:: bash

   $> java -jar ./OESample1.jar
   mol has 10 atoms


