This chapter describes how to set up JDeveloper to build and run Coherence-based Java applications.
To start and configure JDeveloper for use with Coherence:
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:
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
Include %JAVA_HOME%\bin in the PATH environment variable. For example:
set PATH=%JAVA_HOME%\bin;%PATH%
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.
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.
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.
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.
Click Libraries and Classpath, and click the Add Library button. The Add Library dialog box opens.
In the Add Library dialog box, click New.
The Create Library dialog box opens.
Click Add Entry to open the Select Path Entry dialog box.
Find and expand the coherence\lib directory, which is under the \oracle\product.
Highlight and select the coherence.jar file to add it to the classpath. Click OK to return to the Create Library dialog box.
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:
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.
This section describes common tasks that are a part of building projects in JDeveloper.
To create a new application in JDeveloper:
Choose File then New... to open the New Gallery.
Choose General then Application in the Categories section of the New Gallery dialog box and Generic Application in the Items section. Click OK.
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.
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.
To create a project in an existing application:
Right-click the Coherence application and choose New... In the New Gallery choose Projects under Categories and Generic Project under Items. Click OK.
Enter a Project Name, ensure that the Default Package is set correctly, and select a Project Technology if necessary. Click Finish.
To create a new Java class in JDeveloper:
Right-click the project entry in the Navigator pane and select New.
Select Java under the General category and select Java Class. Click OK.
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.
To change the project's runtime properties in JDeveloper:
Right click the project and select Project Properties.
In the Project Properties dialog box select Run/Debug/Profile and click Edit.
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.
Click OK in the Edit Run Configuration dialog box and OK in the Project Properties dialog box to return to the JDeveloper IDE.
To add JAR files or libraries to the project classpath:
Right click the project and select Project Properties.
In the Project Properties dialog box select Libraries and Classpaths and click Add JAR/Directory.
Navigate to the JAR file or directory that you want to include in the classpath.
Click Select in the Add Archive or Directory dialog box. Click OK in the Project Properties dialog box.