To give a broad overview of how the Java-ECLiPSe Interface works, we take a closer look at QuickTest.java. Here is the Java source code from QuickTest.java.
import com.parctechnologies.eclipse.*; import java.io.*; public class QuickTest { public static void main(String[] args) throws Exception { // Create some default Eclipse options EclipseEngineOptions eclipseEngineOptions = new EclipseEngineOptions(); // Object representing the Eclipse engine EclipseEngine eclipse; // Connect the Eclipse's standard streams to the JVM's eclipseEngineOptions.setUseQueues(false); // Initialise Eclipse eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions); // Write a message eclipse.rpc("write(output, 'hello world'), flush(output)"); // Destroy the Eclipse engine ((EmbeddedEclipse) eclipse).destroy(); } }
The structure of the main method in QuickTest.java contains elements which will appear in any Java code which uses the Java-ECLiPSe interface. These are as follows:
Note the first line using import. We need to have this in every Java source file which uses the Java-ECLiPSe Interface so that it can load classes from the package.
EclipseConnection and its subinterface EclipseEngine are Java interfaces which contain the methods used when interacting with ECLiPSe.
There are a number of classes which implement these interfaces. In the case of QuickTest.java we use an instance of EmbeddedEclipse . The initialisation of these implementing classes varies from class to class. In the case of EmbeddedEclipse initialisation is done by creating and configuring an EclipseEngineOptions object and using this in an invocation of the EmbeddedEclipse class’ static method getInstance.
We interact with the ECLiPSe engine by invoking methods on the object which implements EclipseConnection or EclipseEngine . In the case of QuickTest.java we invoke the rpc method, which causes the ECLiPSe to execute a goal, in this case one which simply prints a message.
In order to clean up, after the Java program has finished interacting with ECLiPSe, the interaction should be terminated. Like initialisation, how this termination is done varies among the classes which implement the EclipseConnection and EclipseEngine interfaces. In the case of QuickTest.java, termination is done by invoking the destroy method on the EmbeddedEclipse object.