Cougaar “Hello World” Demo
NOTE: This file and all referenced files are included in the demo-hello.zip of the latest Cougaar release.
This module contains the Cougaar “Hello World” demo.
This is a bare-minimum Cougaar demo. A single plugin simply prints “Hello, world!”.
For additional information and demos, please see the Cougaar Overview Slides Slides.
Contents:
- configs/HelloSociety.xml: The society configuration file.
- run/SingleNodeRuntime.xml: The runtime configuration file.
- run/logging.props: The Log4j logging configuration file.
- lib/hello.jar: The compiled source code.
- src/org/cougaar/demo/hello/HelloPlugin.java: The source code.
- build.xml: An Ant script to recompile the code.
Installation:
- Verify that Java 1.5 or 1.6 is installed and is on the PATH:
java -version - Create a Cougaar install directory, e.g.:
mkdir /usr/local/cougaar
Set this directory as the COUGAAR_INSTALL_PATH environment variable:
export COUGAAR_INSTALL_PATH=/usr/local/cougaar
This directory can optionally be shared and read-only. - Download Cougaar 12.2 or later. The Releases and latest nightly builds can be found at Downloads.
- Unzip the “cougaar.zip” and “cougaar-support.zip” into the COUGAAR_INSTALL_PATH.
- Optionally add the “$COUGAAR_INSTALL_PATH/bin/cougaar” script to the command-line search PATH:
export PATH=$COUGAAR_INSTALL_PATH/bin:$PATH
This can also be done by adding the following line to your “~/.bashrc”:
function cougaar() { $COUGAAR_INSTALL_PATH/bin/cougaar $* ; } - Create a per-user Cougaar “user” directory, e.g.:
mkdir ~/cougaar
Applications and demos will go into this directory.This directory can be the same as the COUGAAR_INSTALL_PATH, but (in general) it is cleaner to keep these directories separate.The Cougaar “user” directory will be the Eclipse “workspace” directory. - Move the “hello/” directory into your Cougaar “user” directory.If you’re using the “demo-hello.zip”, then unzip this zip into your Cougaar “user” directory. The “demo-hello.zip” is created by the nightly build.
- Set the COUGAAR_SOCIETY_PATH environment variable:
export COUGAAR_SOCIETY_PATH=~/cougaar/hello
The COUGAAR_SOCIETY_PATH will be the Eclipse “project” directory. - Set the COUGAAR_RUNTIME_PATH environment variable:
export COUGAAR_RUNTIME_PATH=$COUGAAR_SOCIETY_PATH/run
This directory will contain the “runtime” XML file, which defines the Java System Properties, and will contain any output logs and other per-run temporary files.For simplicity, this directory is packaged as the “run/” subdirectory of the COUGAAR_SOCIETY_PATH. Users can move and rename this “run” directory to any location, so long as the COUGAAR_RUNTIME_PATH environment variable is set correctly and the directory is writable.The COUGAAR_RUNTIME_PATH will be the Eclipse “working” directory. - Compile the source code to create the “lib/hello.jar”:
ant dist
If you’ve unzipped the “demo-hello.zip” then this step is optional. The zip includes a pre-compiled “lib/hello.jar”.
Usage:
- From the command line:
cd $COUGAAR_RUNTIME_PATH cougaar -v $COUGAAR_SOCIETY_PATH/configs/HelloSociety.xml SingleNodeRuntime.xml
This should print:
[HelloPlugin] – A: Hello, world!To stop the run, press “CTRL-C”. - From Eclipse (or any other IDE):We are working to enhance the Cougaar Eclipse Plugin to simplify the configuration of Cougaar within Eclipse.For now, Eclipse can be configured to run Cougaar just like any other Java application.As noted above, the important paths are:
- The Eclipse “workspace” directory is the parent directory of the $COUGAAR_SOCIETY_PATH
- The Eclipse “project” directory is the $COUGAAR_SOCIETY_PATH
- The Eclipse “working” directory is the $COUGAAR_RUNTIME_PATH
The required Java system properties are illustrated in the above command-line “cougaar -v” output.
java options:
# specified on the command line:
-Dorg.cougaar.society.file=$COUGAAR_SOCIETY_PATH/configs/HelloSociety.xml
-Dorg.cougaar.runtime.file=SingleNodeRuntime.xml
# the first node specified in HelloSociety.xml
-Dorg.cougaar.node.name=Node1
# extracted from SingleNodeRuntime.xml
-Dorg.cougaar.society.xsl.param.template=single_node
-Dorg.cougaar.core.logging.config.filename=logging.props
# our environment variables
-Dorg.cougaar.install.path=$COUGAAR_INSTALL_PATH
-Dorg.cougaar.society.path=$COUGAAR_SOCIETY_PATH
-Dorg.cougaar.runtime.path=$COUGAAR_RUNTIME_PATH
# boilerplate
-Dorg.cougaar.bootstrap.application=org.cougaar.core.node.Node
-Dorg.cougaar.core.node.InitializationComponent=XML
-Dorg.cougaar.core.persistence.verifyJavaIOPatch=false
# the classpath, which ALWAYS ONLY contains the Cougaar jar locator
-Djava.class.path=$COUGAAR_INSTALL_PATH/lib/bootstrap.jar
# the "main()" class
org.cougaar.bootstrap.Bootstrapper