White Papers
Abstract
The purpose of this whitepaper is to demonstrate how an existing JavaFX project can be imported into and Built with IBM Rational Rhapsody in Java. We will be using the BrickBreaker example from the Oracle website. To demonstrate how IBM Rational Rhapsody can adopt to different situations, we will avoid modifying of the example source code in this guide. Instead we will show how to remedy issues by modifying the project settings to fit with the example code. Of course, it may be better coding practice to “correct” some of the issues within the code directly.
n.b. Password for zip project is rhapsody.
Content
Procedure:
- Download and install Java JDK 1.7 u60 or higher.
- Download the BrickBreaker example found in the JavaFX Demos and Samples Downloads from Oracle Java SE Development Kit 7 Downloads -
- Reverse engineer the src\BrickBreaker folder JavaFX example.

You should now have the package for the BrickBreaker project and also the Java/JavaFX external classes referenced by the BrickBreaker code

4) Generate the code. The classes under Java/JavaFX are marked as external as we don’t want to generate these source files. We want to reference the pre-compiled libraries in the JRE (See step 1)
5) If we try to build the code now we will get a lot of errors because the JavaFX library: jfxrt.jar cannot be found. For example,

Open the DefaultComponent and add the path to this file in the CLASSPATH field.
For example, I installed the JDK1.7.0_67 to C:\Program Files\Java\jdk1.7.0_67 so I want to add the following line to the DefaultComponent:

6) Any compile errors may be due to a bad import from the RE engine. For example, with the error below:

The code should be
private static java.util.Random RANDOM = new java.util.Random();We can remedy this by
a) opening Utils::Random in the browser and setting the Attribute type to a non-existing type “java.util.Random”.

b) Leave the code as it was imported and add the missing external class called Random to Java.util package and a usage dependency from Utils to Random:

7) Next we need to configure the entrypoint for the project. We currently have the default entry point in the configuration that does nothing, and the imported entry point in the Main class:

Clearly we need to reconcile the two. There are several ways to do this:
a) Merge the imported Main class into the MainDefaultComponent class that was created by IBM Rational Rhapsody.
b) Call the Main.main function from the MainDefaultComponent.main method.
The latter is a much quicker approach but is messier.
For this guide I will use the latter approach.

8) We also need to make sure that we build and run the project with the same and correct versions of the javac and java respectively. Open jdkmake.bat and jdkrun.bat from the Rhapsody\Share\etc directory and check the PATH variable assignments match your download JDK from step 1.

If this is not set properly you will likely get a runtime error. Something similar to
RenderJob.run: internal exception
java.lang.UnsatisfiedLinkError: com.sun.prism.d3d.D3DContext.nSetBlendEnabled
9) In the BlockBreaker example, you will need to move a resources folder, images, to your project location. N.b. it would be better coding practice to modify the source code so that the hard-coded folder path is outside of the code directory.
The code should now run from the IBM Rational Rhapsody toolbar.
Was this topic helpful?
Document Information
Modified date:
04 August 2020
UID
swg27043637