Skip to main content

Creating A Java Projection

To create a Java Projection for a Caché class, add a %Projection.JavaOpens in a new tab property to the class definition. When you compile the class, the Java Class Generator automatically generates the source file for the projection. Here are instructions for adding a Java Projection to JavaTutorial.Contact using Studio's New Projection Wizard. If you have not yet loaded this class into a namespace within your Caché installation, click here for instructions.

  1. Open Studio by clicking on the Caché cube and selecting Studio.

  2. Connect to the namespace containing JavaTutorial.Contact by clicking File —> Change Namespace and then clicking the appropriate namespace.

  3. In the WorkSpace window's Namespace tab, open the JavaTutorial folder and then double-click Contact. Studio displays the class definition for Contact in the Class Editor.

  4. Click Class —> Add —> Projection on the menu bar.

  5. Enter a name for the projection, for example JavaProjection. Click Next.

  6. Select a Projection Type. Click %Projection.Java on the drop-down list.

  7. Enter a value for the projection's ROOTDIR parameter, for example, <cachesys>\dev\java\tutorials\java. Caché creates a new subdirectory containing the source file for the projection in this directory. Click Finish.

  8. The Class Editor adds the following declaration to the JavaTutorial.Contact definition:

    Projection JavaProjection As
     %Projection.Java(ROOTDIR = "<cachesys>\dev\tutorials\java");
    

    Note that you can add the projection directly using the Class Editor window rather than through the New Projection Wizard.

    Note also that there are several parameters that you can add to the projection in addition to ROOTDIR. These parameters control various aspects of the projection process and can impact the efficiency of the generation and compilation of the projection class. See the class documentation for %Projection.JavaOpens in a new tab for details.

  9. Deselect the skip related up-to-date classes compiler flag. In Studio, click Tools -> Options. Under Compiler -> Flags & Optimization uncheck skip related up-to-date classes. Click OK.

  10. Compile Contact by selecting Build —> Compile from the menu bar.

  11. The Java Class Generator creates the Java source file for the projection — Contact.java. Since Contact depends on PhoneNumber, the system automatically creates the source file for a Java Projection of PhoneNumber as well — PhoneNumber.java. Caché places both files in a subdirectory, named JavaTutorial, of the directory specified as the value of the ROOTDIR parameter.

  12. Compile the Java projections using your Java compiler.

Note:

In a standard Windows installation <cachesys> is C:\InterSystems\Cache. In a standard UNIX® or Linux installation it is /usr/cachesys.

Caché places Java projection source files in directories with names reflecting their package names. This is because Java Platforms typically expect to find both source and class files in directories with names matching package names. By default the projection package name is the same as the Caché package name.

Both cachejdbc.jar and cachedb.jar must be on the classpath when you compile. The Java 1.7 versions of these files are in <cachesys>\dev\java\lib\JDK17\. The Java 1.8 versions are in <cachesys>\dev\java\lib\JDK18\. Please use the appropriate versions for your compiler.

The directory containing the class files for the projections must be on your application's classpath.

For more information on using Studio, read Using Studio.

FeedbackOpens in a new tab