Skip navigation.
Home

Adding External JARs to Ptolemy II Environment

1. Introduction

We want to use the Ptolemy II to integrate two models (one is Repast S model written in java, the other is python model written in python), and control these two models running synchronously.

2. Integration Issues

In the windows installer version of Ptolemy II,we cannot invoke the Repast Simphony model application that uses classes in Repast Simphony runtime and core jars ,and also we cannot add such jars to Ptolemy II runtime environment classpath. So we download the source file of Ptolemy II, and use eclipse to create a project from the Ptolemy source file, add Repast Simphony jars, rebuild the Ptolemy II project.

3. Building Ptolemy II from source file

3.1. Eclipse preference for Ptolemy II

1. We will need to change the default memory size for Eclipse because Ptolemy II is a big project. In Windows, create a shortcut to eclipse.exe on your desktop. Then right mouse click on the shortcut and select Properties and change the target to increase the memory allocated by default. E.g., if you installed Eclipse in C:\Program Files\eclipse, then the Target should read:
"C:\Program Files\eclipse\eclipse.exe" -vmargs -Xmx256M
The maximum memory size will now be 256 megabytes when you restart Eclipse.

2. Eclipse requires some customization to build Ptolemy II and to keep the Ptolemy II coding style. In the steps below, we outline changes to be made in the Eclipse Preferences window, which is invoked via Window -> Preferences. For each of the changes, hit "Apply". When all the changes are done, hit "OK", which will close the Eclipse Preferences Window.

3. By default, Eclipse rebuilds a project when any change is made to a file. This will result in thousands of errors when Ptolemy II is first checked out, and during normal usage, can be annoying because of the pauses it creates. We suggest disabling this feature as follows:

1. While still in the preferences window (Window -> Preferences).
2. General -> Workspace
3. Deselect "Build automatically"
4. Click Apply

4. Ptolemy II source files are worked on by many people with different editors. Unfortunately, different text editors interpret tab characters differently, so it is best to use spaces rather than tabs.
Sadly, the Eclipse developers have chosen to use tabs as spaces, so you must adjust the Eclipse Java Formatter if you plan on contributing code to the Ptolemy II tree.
Also, it is best if files end with new line characters, so that we can run line oriented scripts on them.
In addition, we currently do not want the Eclipse Formatter to format comments. We hope to change this policy in the future.
We handle these changes together:

1. While still in the preferences window (Window -> Preferences).
2. Expand the Java tree, select "Code Style" -> "Formatter"
3. Under "Active profile", click on "New..."
4. In the "New Profile" window, enter "Ptolemy II" into the "Profile Name" entry.
5. Under "Initialize settings with the following profile", select "Java Conventions [built-in]" (We use Java Conventions over the "Eclipse" setting because the Eclipse style uses tabs.)
6. Click on "OK" to close the "New Profile" window
7. A "Profile 'Ptolemy II' window will appear. Under the "Indentation" tab, change the Tab policy to "Spaces only". verify that the Tab policy is "Spaces only".
8. Under the "New Lines" tab, select "at end of file"
9. Under the "Comments" tab, unselect "Enable block comment formatting"
10. Click OK.
11. In the Preferences Window, click Apply

5. Ptolemy II uses some features of Java 5.0. In particular, ptolemy/actor/ptalon uses generics, which require Java 5.0 Set Eclipse to use Java 5.0 source code compliance.

1. While still in the preferences window (Window -> Preferences).
2. Expand the Java tree, select "Compiler" -> "Building"
3. Make sure that Set "Compiler compliance level" is "5.0".
4. Click Apply.

6. Eclipse has very good compiler error/warning. One of the warnings complains if a Serializable class does not have serialVersionUID declared. Since this warning is only useful if you are tightly managing serialization, we turn it off:

1. While still in the preferences window (Window -> Preferences).
2. Expand Team->File Content
3. Click on "Add Extension" and enter "*.tcl" in the "Enter File Extension" window, then click "OK" in the "Enter File Extension"
4. Select "*.tcl" in the "File Content" window and then hit the "Change" button to change the Content to "ASCII Text"
5. Do the same steps for the "*.c" and "*.h" files.
6. Click on "Add Name" and add "makefile", select "makefile" and click on the "Change" button to change the Content to "ASCII Text"
7. Click Apply

3.2. Running Ptolemy II

1. In the Run menu, select "Open Run Dialog".
2. In the resulting dialog, select "Java Application" and click "New".
3. In the dialog, fill in the boxes as follows:

  • Name: Vergil
  • Project: ptII
  • Main class: ptolemy.vergil.VergilApplication

4. Press the Run button.

4. Add Repast S JARS to Ptolemy II Environment

1. In the Ptolemy II root directory, create a directory “simphony/lib”
2. Go to the plugins directory where your Repast Simphony installed, for example: “D:\RepastS\eclipse\plugins”
3.Copy “org.eclipse.emf.common_2.3.0.v200709252135.jar” “org.eclipse.emf.ecore.xmi_2.3.1.v200709252135.jar” “org.eclipse.emf.ecore_2.3.1.v200709252135.jar” these three jar files in “D:\RepastS\eclipse\plugins” to “simphony/lib” (Maybe you used different version Repast S, the three jars’ name may be a little different),
4. Copy all jars in the directory: “D:\RepastS\eclipse\plugins\repast.simphony.core\lib” to “simphony/lib”,/div>

5.Copy all jars in the directory: “D:\RepastS\eclipse\plugins\repast.simphony.runtime\lib” to the lib directory in the SimphonyInvoke project,
6. In the eclipse, refresh the Ptolemy II project, then right click on the, choose “property”>> “Java Build path” >> “Libraries” >> “Add Jars”, add all the jars in “simphony/lib”.
7. Build the Ptolemy II project again.

6. Python Source file Importing Problem

When you start the Ptolemy,try to use the python actors to import python file(That you put in the Ptolemy root directoy) you write in the graphic environment.It will raise the “no such module exception”.The cause of this is that the python interpreter java file doesn’t add the root directory to the jython os path.Here you need to rewrite the PythonScript.java file in the directory “ptolemy\actor\lib\python”
and find part as below,add or change the code to add the root directory.

try {

String ptIIDir = StringUtilities.getProperty("ptolemy.ptII.dir");
_interpreter.exec("import sys\n");
_interpreter.exec("sys.path.append('" + ptIIDir
+ "/vendors/jython/Lib')"); //add the directory to jython’s os path.

}
catch (Exception ex) {
}

7. Start Ptolemy II from a Batch File

To start the Ptolemy out of the eclipse, you just need to write a batch file that is the same as starting a java application form the main class. But here you have to set the jars needed by the Ptolemy and simphony to the classpath. The following is the example that start it.

@ECHO OFF
TITLE Vergil

REM Add the ptolemy needed jar files

SET CLASSPATH=%CLASSPATH%;lib/ptCal.jar
SET CLASSPATH=%CLASSPATH%;lib/java_cup.jar
SET CLASSPATH=%CLASSPATH%;lib/saxon8.jar
SET CLASSPATH=%CLASSPATH%;lib/saxon8-dom.jar
SET CLASSPATH=%CLASSPATH%;lib/chic.jar
SET CLASSPATH=%CLASSPATH%;lib/jython.jar
SET CLASSPATH=%CLASSPATH%;lib/ptjacl.jar
SET CLASSPATH=%CLASSPATH%;lib/mapss.jar
SET CLASSPATH=%CLASSPATH%;lib/sootclasses.jar
SET CLASSPATH=%CLASSPATH%;lib/jasminclasses.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/distributed/jini/jar/jini-core.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/distributed/jini/jar/jini-ext.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/distributed/jini/jar/sun-util.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/domains/ptinyos/lib/jdom.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/domains/ptinyos/lib/nesc.jar
SET CLASSPATH=%CLASSPATH%;ptolemy/actor/ptalon/antlr/antlr.jar

REM Add the simphony needed jar files
set LIB=simphony/lib/

SET CLASSPATH=%CLASSPATH%;%LIB%cglib-nodep-2.1_3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%collections-generic-4.01.jar
SET CLASSPATH=%CLASSPATH%;%LIB%colt-1.2.0.jar
SET CLASSPATH=%CLASSPATH%;%LIB%commons-cli-1.0.jar
SET CLASSPATH=%CLASSPATH%;%LIB%commons-collections-3.2.jar
SET CLASSPATH=%CLASSPATH%;%LIB%commons-lang-2.1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%commons-logging-1.0.4.jar
SET CLASSPATH=%CLASSPATH%;%LIB%concurrent-1.3.4.jar
SET CLASSPATH=%CLASSPATH%;%LIB%geoapi-nogenerics-2.1-M2.jar
SET CLASSPATH=%CLASSPATH%;%LIB%groovy-all-1.0.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-api-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-arcgrid-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-brewer-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-coverage-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-epsg-hsql-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-indexed-shapefile-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-main-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-referencing-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-render-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%gt2-shapefile-2.3.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%hsqldb-1.8.0.1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%imageioext-asciigrid-1.0-rc1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%javassist-3.1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jgap.jar
SET CLASSPATH=%CLASSPATH%;%LIB%joone.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jpf.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jpf-boot.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jscience.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jsr108-0.01.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jts-1.7.1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jung-algorithms-2.0-alpha2.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jung-api-2.0-alpha2.jar
SET CLASSPATH=%CLASSPATH%;%LIB%jung-graph-impl-2.0-alpha2.jar
SET CLASSPATH=%CLASSPATH%;%LIB%log4j-1.2.13.jar
SET CLASSPATH=%CLASSPATH%;%LIB%opencsv-1.5.jar
SET CLASSPATH=%CLASSPATH%;%LIB%OpenForecast-0.4.0.jar
SET CLASSPATH=%CLASSPATH%;%LIB%org.eclipse.emf.common_2.3.0.v200709252135.jar
SETCLASSPATH=%CLASSPATH%;%LIB%org.eclipse.emf.ecore.xmi_2.3.1.v200709252135.jar
SET CLASSPATH=%CLASSPATH%;%LIB%org.eclipse.emf.ecore_2.3.1.v200709252135.jar
SET CLASSPATH=%CLASSPATH%;%LIB%ProActive.jar
SET CLASSPATH=%CLASSPATH%;%LIB%repast.simphony.bin_and_src.jar
SET CLASSPATH=%CLASSPATH%;%LIB%saf.core.runtime.jar
SET CLASSPATH=%CLASSPATH%;%LIB%vecmath-1.3.1.jar
SET CLASSPATH=%CLASSPATH%;%LIB%velocity-1.4.jar
SET CLASSPATH=%CLASSPATH%;%LIB%xercesImpl.jar
SET CLASSPATH=%CLASSPATH%;%LIB%xml-apis.jar
SET CLASSPATH=%CLASSPATH%;%LIB%xpp3-1.1.3.4d_b4_min.jar
SET CLASSPATH=%CLASSPATH%;%LIB%xstream-1.1.3.jar
SET CLASSPATH=%CLASSPATH%;%LIB%hello.jar

REM Start the ptolemy from the main class
START javaw -Xss10M -Xmx400M ptolemy.vergil.VergilApplication

Latest image