CMI Tutorial - WPI



Executive Summary

This short tutorial shows how to create two sample block components using the original CMI Version 1.0. The first block is a simple Input component that reads two numbers from the user and relies on a second block Calculator component to produce results.

1. Assumptions

I assume you have access to the Java virtual machine and compiler. To check if this is true, type “java –version” at the command prompt in Unix or the DOS prompt in Microsoft Windows. If the command does not execute, you have not properly installed the software. Grab the latest from . The most common fix is to set your PATH variable to appropriate point to the right location. Another alternative is to enter the full path for the java executable as it is located on your machine.

I assume that you have downloaded the CMITutorial_v1.zip file. If you are running Eclipse, then you should continue that tutorial now (see the CMI Eclipse Tutorial).

If you are not using Eclipse (or would like to see how this technology is used outside of Eclipse) you should extract the files into some directory (in this document we will refer to that directory as DIR). NOTE: Because of java-specific mechanisms, this CMI will only work with Java JDK of version 1.2 and higher. The CCC machines will satisfy this requirement, so will many integrated java development environments.

I assume you will either operate fully within Eclipse or you are comfortable working “natively” on your computer. I encourage the use of Eclipse especially because it will make your life bearable in this course (.

2. Compiling Block Components

First, we assume you are not using an IDE such as Eclipse, but are simply working at the Unix or DOS prompt. Create a directory in which to work (we’ll call this DIR) and unzip the CMITutorial_v1.zip files inside that directory.

Change to the DIR directory. To compile the Calculator block component, type the following command within DIR to invoke the Java compiler:

|Windows |javac calculator\Calculator.java |

|Un*x |javac calculator/Calculator.java |

If your code does not compile, then you will need to set your CLASSPATH variable appropriately to include the current directory (.) in the path. The following commands will set the CLASSPATH appropriately; if you have a different shell (and especially on DOS machines), the syntax will be different:

|Un*x |export CLASSPATH=DIR:$CLASSPATH |

|KSH | |

|Un*x |setenv CLASSPATH DIR:$CLASSPATH |

|CSH | |

|Windows |set PATH=DIR;%CLASSPATH% |

|DOS | |

|Windows |export PATH=”DIR;$CLASSPATH” |

|Cygwin | |

Note that DIR above must be replaced with the absolute path name on your file system where you installed the software. If you intend to run the javac compiler within the DIR directory, then you can replace DIR in the above table with a single period ‘.’. For example on windows/DOS you could say “set PATH=.;%CLASSPATH%”.

Note that to be safe you should append any existing CLASSPATH values to the end. Also, if you are running on a PC, the ";" character will be used to separate directories within the CLASSPATH, as follows:

Now when I type the javac Command, I get no errors. Now compile the other component in the tutorial directory:

|Windows |javac tutorial\FirstTry.java |

|Un*x |javac tutorial/FirstTry.java |

Ignore the warning message about using a deprecated API.

3. Packaging Block components

To Package these block components, use the jar command to create two Java archive files. Execute these two commands in DIR (if you can’t execute a command called jar then you have not properly installed the Java JDK but rather installed the JRE only; make sure you have the JDK installed).

jar cvf calculator.jar calculator

jar cvf tutorial.jar tutorial

You will see output such as:

added manifest

adding: calculator/(in = 0) (out= 0)(stored 0%)

adding: calculator/Calculator.java(in = 2289) (out= 714)(deflated 68%)

adding: calculator/Calculator.class(in = 982) (out= 558)(deflated 43%)

4. Deploying Block components

Now you must deploy your components. This process simply means that you must place the Jar file contains the block components into a location that will be found by the scripts loaded by CMI. Move the created calc.jar and tutorial.jar files into the DIR/blocks directory.

5. Write Foundation scripts

These are in the tutorial example directory scripts. Make sure you understand what these scripts are doing. Note that block components are first instantiated, then connected, then finally activated. The deactivation script is for components that need to clean up after they have executed.

6. Run CMI Foundation

If your CLASSPATH is set up as before, you can execute the command within DIR as follows:

java oldcmi.Foundation

Note: without arguments, you get the following usage information

Usage: java oldcmi.Foundation

is directory where scripts are located.

is directory for persistentStorage.

is directory where block .jar files exist.

So type the final command:

java oldcmi.Foundation scripts storage blocks

Note: Foundation will create the storage directory for you if one does not already exist.

7. Run Block Application

Now when run, you can enter in pairs of numbers that will be computed for you. Enter “-1 –1” to terminate the application, and thus foundation.

References

1. CMI Eclipse Tutorial ()

2. CMI Tutorial Files ()

3. CMI Tutorial Document ()

|Version |Date |Change(s) |

|1.0 |12/27/2004 |Prepared for 1st class. |

|1.1 |1/19/05 |Updates for class. |

|1.2 |3/8/2007 |Updates for class |

-----------------------

|Status Information |

|Version |1.2 |

|Online Version| |

| |CMI_v1_Tutorial.doc |

|Editing |3/8/2007 |

|History | |

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download