Home > Coherence, Java, Oracle > Running a Coherence Application in Eclipse

Running a Coherence Application in Eclipse

This is the Part 2 of my Coherence Series.

The first one is Preparing Eclipse OEPE for Oracle Coherence.

In this post I am trying to explain to run a demo coherence application inside the Eclipse.

1 ) First of all I created these packages under the src folder of project:


And the files should be placed in these folders as shown in below:


  • Customer.java


  • CustomerTest1.java


  • coherence-cache-config.xml
  • pof-config.xml
  • tangosol-coherence-override.xml

2 ) Customer class is a bean and it has getter and setter methods. Also because of it implements the PortableObject there are methods which should be implemented in the class, readExternal and writeExternal.

Customer.java is here:

package com.afsungur.coherence.objects;import java.io.IOException;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;

public class Customer implements PortableObject{
private String surName;
private String address;
private String email;
private String mobileTelephoneNumber;
private int zipCode;
private String name;

* @param name
* @param surName
* @param address
* @param email
* @param mobileTelephoneNumber
* @param zipCode
public Customer(String name, String surName, String address, String email,
String mobileTelephoneNumber, int zipCode) {
this.name = name;
this.surName = surName;
this.address = address;
this.email = email;
this.mobileTelephoneNumber = mobileTelephoneNumber;
this.zipCode = zipCode;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

public String getSurName() {
return surName;

public void setSurName(String surName) {
this.surName = surName;

public String getAddress() {
return address;

public void setAddress(String address) {
this.address = address;

public String getEmail() {
return email;

public void setEmail(String email) {
this.email = email;

public String getMobileTelephoneNumber() {
return mobileTelephoneNumber;

public void setMobileTelephoneNumber(String mobileTelephoneNumber) {
this.mobileTelephoneNumber = mobileTelephoneNumber;

public int getZipCode() {
return zipCode;

public void setZipCode(int zipCode) {
this.zipCode = zipCode;

public void readExternal(PofReader pofReader) throws IOException {
// TODO Auto-generated method stub
name = pofReader.readString(NAME);
surName = pofReader.readString(SURNAME);
address = pofReader.readString(ADDRESS);
email = pofReader.readString(EMAIL);
mobileTelephoneNumber = pofReader.readString(MOBILETELEPHONENUMBER);
zipCode = pofReader.readInt(ZIPCODE);


public void writeExternal(PofWriter pofWriter) throws IOException {
// TODO Auto-generated method stub
pofWriter.writeString(SURNAME, surName);
pofWriter.writeString(ADDRESS, address);
pofWriter.writeString(EMAIL, email);
pofWriter.writeString(MOBILETELEPHONENUMBER, mobileTelephoneNumber);
pofWriter.writeInt(ZIPCODE, zipCode);

private final int NAME=0;
private final int SURNAME=1;
private final int ADDRESS=2;
private final int EMAIL=3;
private final int MOBILETELEPHONENUMBER=4;
private final int ZIPCODE=5;


3) CustomerTest1 class is tester class. It creates a customer object and put this object into the customer cache. And also it prints the cache size.

package com.afsungur.coherence.test;

import com.afsungur.coherence.objects.Customer;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class CustomerTest1 {

public static void main(String args[])
Customer cust = new Customer("Ahmet Fuat", "Sungur", "Bahcelievler/Istanbul", "afsungur@gmail.com", "5321231231", 34111);

NamedCache cache = CacheFactory.getCache("customers");
cache.put(1, cust) ;
System.out.println("Cache Size:"+cache.size());



4) coherence-cache-config.xml file includes the cache features like expiring time, cache size, cache type. I will explain some features in detail but in this example I used this cache config xml :

<?xml version="1.0"?><cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
<!-- each node will be limited to 32MB -->
Invocation Service scheme.

<autostart system-property="tangosol.coherence.invocation.autostart">true</autostart>


5) pof-config.xml file includes the serialized object list which are used inside the project. In this example Customer class should be specified inside the pof-config.xml file. My pof-config.xml file’s content is :

<?xml version="1.0"?>
<pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof-config http://xmlns.oracle.com/coherence/coherence-pof-config/1.1/coherence-pof-config.xsd">
<!-- include all "standard" Coherence POF user types -->

6) tangosol-coherence-override.xml file includes the cache server feature settings. I am using the default one, I didn’t change anything. Cache server attributes can also be modified in “Run Configurations” menu.

7) So far, I explained the files to run our first test application. In the package explorer you should see the same picture as shown in below:

Coherence Project 1 Package Explorer

But also we should set some coherence configurations to run this application. To do this, first Right Click of project and then select Run As -> Run Configurations

8) In the opened window, at the left side right click Oracle Coherence then click New.

Give a name for this configuration, select project and select main class as shown in below.

Coherence Test Configuration

9 ) Then select Coherence tab and specify the coherence-cache-config.xml file in the Topology section.

Cache Configuration

And at the same window, in the bottom section you should specify the multicast/unicast port/ip settings. You should specify the port number which has not be used yet. You can specify the parameters as shown in below

MultiCast Port

10 ) In Coherence main tab, select the Other sub-tab as shown in below:

Other Tab

Then at the bottom of this window there is a parameter, tangosol-pof-config. On this row at the right side there is a path. You should specify the pof-config.xml path which has already written before ( In step 5 you created the pof-config.xml )

Pof Config

11 ) After you successfully completed these steps, we need to test application. In the “Run Configurations” window, click Run and observe the results.

Console Output

In next post I will explain this output briefly.

  1. sravanth
    November 25, 2014 at 10:01 am

    Do we need to have specific version of eclipse?
    While trying to do the above steps the Coherence tab at project Facets is not available. Please confirm me.

    • Ahmet Fuat Sungur
      November 26, 2014 at 10:19 am

      You need to install Oracle Enterprise Pack for Eclipse.

  1. August 21, 2012 at 7:29 pm
  2. August 23, 2012 at 6:41 am
  3. August 29, 2012 at 10:23 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: