8/19

# 2 Using JDeveloper with Coherence

This chapter describes how to set up JDeveloper to build and run Coherence-based Java applications.

- Configuring Oracle JDeveloper for Coherence

- Learning JDeveloper Basics

## 2.1 Configuring Oracle JDeveloper for Coherence

To start and configure JDeveloper for use with Coherence:

1. Open a terminal window and verify that the `PATH` environment variable is set to include the Java JDK; for example: `\oracle\product\jdk160_14_R27.6.5-32\bin`. Note that this tutorial assumes that you have a working installation of Java SE (JDK) version 1.6 or higher.

   If the `PATH` environment variable does not include the Java JDK `\bin` directory, then set the variable as follows:

   1. Set the `JAVA_HOME` environment variable to the base of the JDK installation. For example:

          set JAVA_HOME=\oracle\product\jdk160_14_R27.6.5-32

   2. Include `%JAVA_HOME%\bin` in the PATH environment variable. For example:

          set PATH=%JAVA_HOME%\bin;%PATH%

   3. Start JDeveloper. If you get a message asking you to select a role, select Default Role. If you get a message asking whether you want to migrate from previous versions of JDeveloper, select No. Close any window that displays the Tip of the Day.

      Figure 2-1 Select Role Dialog Box

2. After JDeveloper starts, select File then New to open the New Gallery. Select Generic Application in the Items column to create an application. An application is a way of grouping projects or source code. This new application will hold the Coherence projects.

3. In the Create Generic Application dialog box, change the application name to `Coherence`, the directory path to `\home\oracle\labs`, and the application package prefix to `com.oracle.handson`. Click Finish.

   Figure 2-2 illustrates the Create Generic Application dialog box.

   Figure 2-2 Creating an Application in JDeveloper

4. Add the Coherence JAR files to the default project properties. Right click the project in the Application Navigator and select Project Properties. The Project Properties dialog box opens.

   Figure 2-3 Default Properties Dialog Box

5. Click Libraries and Classpath, and click the Add Library button. The Add Library dialog box opens.

   Figure 2-4 Add Library Dialog Box

6. In the Add Library dialog box, click New.

   The Create Library dialog box opens.

   Figure 2-5 Create Library Dialog Box

7. Click Add Entry to open the Select Path Entry dialog box.

   Find and expand the `coherence`\`lib` directory, which is under the `\oracle\product`.

8. Highlight and select the `coherence.jar` file to add it to the classpath. Click OK to return to the Create Library dialog box.

   Figure 2-6 Select Path Entry Dialog Box

9. In the Create Library dialog box, change the name in the Library Name field to Coherence. Use the drop-down list to change the Location value from Project to User. The contents of the dialog box should look like this:

   Figure 2-7 Create Library Dialog Box with the Coherence Jar on the Classpath

10. Click OK in the Create Library, Add Library, and Default Project Properties dialog boxes to return to the JDeveloper IDE. Oracle JDeveloper is now set up with the correct Coherence libraries.

## 2.2 Learning JDeveloper Basics

This section describes common tasks that are a part of building projects in JDeveloper.

- Creating a New Application and Project

- Creating a Java Class

- Changing Project Properties, Setting Runtime Configuration

### 2.2.1 Creating a New Application and Project

To create a new application in JDeveloper:

1. Choose File then New... to open the New Gallery.

2. Choose General then Application in the Categories section of the New Gallery dialog box and Generic Application in the Items section. Click OK.

   Figure 2-8 Creating a New Application in the New Gallery

3. In the Create Generic Application dialog box, enter the name the project.

   - Replace Application1 with the name of your application.

   - Ensure that directory path to the project is correct.

   - Click Next.

   Figure 2-9 Providing an Application Name

4. JDeveloper asks you to create a new project within the application. Enter a name for the project. If necessary, select a project technology from the Available list. Click Finish to create the new project.

   Figure 2-10 Providing a Project Name

### 2.2.2 Creating a New Project in an Existing Application

To create a project in an existing application:

1. Right-click the Coherence application and choose New... In the New Gallery choose Projects under Categories and Generic Project under Items. Click OK.

   Figure 2-11 Creating a New Project in an Existing Application

2. Enter a Project Name, ensure that the Default Package is set correctly, and select a Project Technology if necessary. Click Finish.

   Figure 2-12 Providing Details for the New Project

### 2.2.3 Creating a Java Class

To create a new Java class in JDeveloper:

1. Right-click the project entry in the Navigator pane and select New.

2. Select Java under the General category and select Java Class. Click OK.

   Figure 2-13 Creating a Java Class in the New Gallery

3. Replace Class1 with the name of your class. Select the Main Method check box if the file must be runnable. Click OK to create the Java class.

   Figure 2-14 Providing Details for the Java Class

### 2.2.4 Changing Project Properties, Setting Runtime Configuration

To change the project's runtime properties in JDeveloper:

1. Right click the project and select Project Properties.

2. In the Project Properties dialog box select Run/Debug/Profile and click Edit.

   Figure 2-15 Project Properties Dialog Box

3. You can set a number of values in the Edit Run Configuration dialog box:

   - Set Virtual Machine to client.

   - Set values for local storage and log level in the Java Options field.

     By default, all processes start as storage-enabled. The process can store data as part of the cluster. You can modify the process so that it is not storage-enabled by using the system property `-Dtangosol.coherence.distributed.localstorage`. Setting the property to `false` specifies that the process is not storage-enabled.

     The `-Dtangosol.coherence.log.level` Java option sets the level of logging. For example:

         -Dtangosol.coherence.distributed.localstorage=false -Dtangosol.coherence.log.level=3

     Later chapters will describe when and how to set these system properties.

   Figure 2-16 Setting the Runtime Configuration

4. Click OK in the Edit Run Configuration dialog box and OK in the Project Properties dialog box to return to the JDeveloper IDE.

### 2.2.5 Adding JARS and Libraries to the Project Classpath

To add JAR files or libraries to the project classpath:

1. Right click the project and select Project Properties.

2. In the Project Properties dialog box select Libraries and Classpaths and click Add JAR/Directory.

3. Navigate to the JAR file or directory that you want to include in the classpath.

   Figure 2-17 Adding JARS or Libraries to the Classpath

4. Click Select in the Add Archive or Directory dialog box. Click OK in the Project Properties dialog box.