Setting up Ptolemy II using Maven

Note that building Ptolemy II with Maven requires an Internet connection. The mvn compile step will download modules from the net.

These notes are based on Tristan King's work, see his July 21, 2008 ptolemy-hackers post: updates on ptII maven and actor.io work.

Setting up Maven

  1. Download Maven from http://maven.apache.org/download.html

Install

  1. Download Ptolemy II using svn and set the $PTII environment variable.
    example:
    	  cd /path/to/working/directory/
    	  svn co svn://source.eecs.berkeley.edu/chess/ptII/trunk ptII
    	  export PTII=/path/to/working/directory/ptII
    	
  2. Optional: Delete $PTII/vendors
    example:
    	  rm -r $PTII/vendors
    	
  3. Make sure that when in $PTII, $PTII==pwd:
              bash-3.2$ cd $PTII
              bash-3.2$ echo $PTII
              /Users/cxh/ptII
              bash-3.2$ pwd
              /Users/cxh/ptII
    	
    If the current working directory is a symbolic link to the actual directory where $PTII is located, then be sure to change either $PTII or the current working directory so they both match.
  4. Set MAVEN_OPTS to configure maven to use large amounts of memory
    example:
    	  export MAVEN_OPTS="-Xms512m -Xmx512m -XX:PermSize=48m"
    	
  5. Configure Ptolemy II to Exclude the Eclipse plugi:
              ./configure --without-eclipse
    	
    FIXME: $PTII/pom.xml needs to be extended to include support for Eclipse, see below
  6. Tell Maven about the jar files necessary to compile:
    	  mvn install:install-file -DgroupId=caltrop -DartifactId=ptCal -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/ptCal.jar
    	  mvn install:install-file -DgroupId=chic -DartifactId=chic -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/chic.jar
    	  mvn install:install-file -DgroupId=jacl -DartifactId=jacl -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/ptjacl.jar
    	  mvn install:install-file -DgroupId=javajoystick -DartifactId=joystick -Dversion=0.7 -Dpackaging=jar -Dfile=$PTII/vendors/misc/joystick/Joystick.jar 
    	  mvn install:install-file -DgroupId=jna -DartifactId=jna -Dversion=4.0.0-variadic -Dpackaging=jar -Dfile=$PTII/lib/jna.jar 
    	  mvn install:install-file -DgroupId=jxta -DartifactId=jxtasecurity -Dversion=1.0 -Dpackaging=jar -Dfile=$PTII/vendors/sun/jxta/jxtasecurity.jar
    	  mvn install:install-file -DgroupId=kieler -DartifactId=kieler -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/kieler.jar
    	  mvn install:install-file -DgroupId=mapss -DartifactId=mapss -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/mapss.jar
    	  mvn install:install-file -DgroupId=org.eclipse.jetty -DartifactId=jetty-all -Dversion=8.1.5-v20120716 -Dpackaging=jar -Dfile=$PTII/lib/jetty-all-8.1.5-v20120716.jar
    	  mvn install:install-file -DgroupId=PDFRenderer -DartifactId=PDFRenderer -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/PDFRenderer.jar
    	  mvn install:install-file -DgroupId=javax.servlet -DartifactId=servlet-api -Dversion=3.0.1 -Dpackaging=jar -Dfile=$PTII/lib/javax.servlet-api-3.0.1.jar 
    	  mvn install:install-file -DgroupId=soot -DartifactId=sootclasses -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/sootclasses.jar
    	  mvn install:install-file -DgroupId=jivesoftware -DartifactId=smack -Dversion=3.0.4 -Dpackaging=jar -Dfile=$PTII/lib/smack.jar
    	  mvn install:install-file -DgroupId=org.mobicents.slee.resource.smack -DartifactId=smackx -Dversion=3.0.4 -Dpackaging=jar -Dfile=$PTII/lib/smackx.jar
    	  mvn install:install-file -DgroupId=protobuf -DartifactId=protobuf -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/protobuf-java-2.4.1.jar 
    	  mvn install:install-file -DgroupId=g4ltl -DartifactId=g4ltl -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/g4ltl.jar
    	  mvn install:install-file -DgroupId=socketio -DartifactId=socketio -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/socketio.jar
    	  mvn install:install-file -DgroupId=oscP5 -DartifactId=oscP5 -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/lib/oscP5.jar
    	
    $PTII/pdb uses db and dbxml, which are basically GPL'd. If you want use ptdb, download db and dbxml from http://www.oracle.com/technology/software/products/berkeley-db/xml/index.html and place them in $PTII/vendors/oracle/, then run:
    	  mvn install:install-file -DgroupId=dbxml -DartifactId=db -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/vendors/oracle/db.jar
    	  mvn install:install-file -DgroupId=dbxml -DartifactId=dbxml -Dversion=ptII -Dpackaging=jar -Dfile=$PTII/vendors/oracle/dbxml.jar
    	
  7. Run vergil! This can be done in a few different ways:
    1. Run vergil using maven.
      example:
      	      cd /path/to/ptII-maven/
      	      mvn compile
      	      mvn exec:exec
      	    
      Note that mvn exec:exec requires net access. To run offline, run: mvn -o exec:exec
    2. Build a ptolemy II jar and run vergil from run-vergil.sh.
      run-vergil.sh would look like:
      	      #!/bin/bash
      	      .java -classpath $PTII/target/ptII-7.1.devel-SNAPSHOT.jar:~/.m2/repository/caltrop/ptCal/unknown/ptCal-unknown.jar:~/.m2/repository/net/jini/jini-core/2.1/jini-core-2.1.jar:~/.m2/repository/antlr/antlr/2.7.6/antlr-2.7.6.jar:~/.m2/repository/javax/jms/jms/1.1/jms-1.1.jar:~/.m2/repository/jdom/jdom/1.0/jdom-1.0.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.15/jre/../lib/tools.jar:~/.m2/repository/chic/chic/unknown/chic-unknown.jar:~/.m2/repository/jxta/jxtasecurity/1.0/jxtasecurity-1.0.jar:~/.m2/repository/jxta/jxta/1.0/jxta-1.0.jar:~/.m2/repository/log4j/log4j/1.2.15/log4j-1.2.15.jar:~/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar:~/.m2/repository/net/jini/jini-ext/2.1/jini-ext-2.1.jar:~/.m2/repository/jython/jython/svn/jython-svn.jar:~/.m2/repository/java3d/j3d-core/1.3.1/j3d-core-1.3.1.jar:~/.m2/repository/jacl/jacl/ptII/jacl-ptII.jar:~/.m2/repository/colt/colt/1.0.3/colt-1.0.3.jar:~/.m2/repository/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar:~/.m2/repository/javajoystick/joystick/0.7/joystick-0.7.jar:~/.m2/repository/mapss/mapss/unknown/mapss-unknown.jar:~/.m2/repository/javax/mail/mail/1.4/mail-1.4.jar:~/.m2/repository/com/sun/jmx/jmxri/1.2.1/jmxri-1.2.1.jar:~/.m2/repository/java3d/vecmath/1.3.1/vecmath-1.3.1.jar:~/.m2/repository/javax/media/jai_core/1.1.2_01/jai_core-1.1.2_01.jar:~/.m2/repository/soot/sootclasses/ptII/sootclasses-ptII.jar:~/.m2/repository/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.jar
      	      ptolemy.vergil.VergilApplication
      	    

      example:
        
      	      # run these two steps only once
      	      cd /path/to/ptII-maven/	
      	      mvn package
      	      # then
      	      /path/to/run-vergil.sh
      	    
      Note that the version numbers are hardwired into the path, which is why this file is not checked in. Another issue is that this command build a jar file, which slows down the build/test cycle.

maven compile fails

Below are various issues that occurred during the build.
What about "make maven"?
mk/ptcommon.mk includes a rule that will create a ptII/src directory. The current ptII/pom.xml file does not use this directory, so there is no need to run make maven
Problem: you need to be on line to compile
	  [INFO] artifact org.apache.maven.plugins:maven-resources-plugin: checking for updates from central
	  [WARNING] repository metadata for: 'artifact org.apache.maven.plugins:maven-resources-plugin' could not be retrieved from repository: central due to an error: Error transferring file
	  [INFO] Repository 'central' will be blacklisted
	
This can happen if there is no network connection when mvn compile is run.
Solution:
Remove ~/.m2/repository/org/apache/maven/plugins/maven-resources-plugin or just remove all of ~/.m2.
Problem: antlr not found
	  Missing:
	  ----------
	  1) antlr:antlr:jar:2.9.9

	  Try downloading the file manually from the project website.

	  Then, install it using the command: 
	  mvn install:install-file -DgroupId=antlr -DartifactId=antlr \
	  -Dversion=2.9.9 -Dpackaging=jar -Dfile=/path/to/file

	  Path to dependency: 
  	  1) edu.berkeley.eecs.ptolemy:ptII:jar:7.1.devel-SNAPSHOT
  	  2) antlr:antlr:jar:2.9.9
	
Solution:
mvn install:install-file -DgroupId=antlr -DartifactId=antlr -Dversion=svn -Dpackaging=jar -Dfile=$PTII/ptolemy/actor/ptalon/antlr/antlr.jar

Then rerun mvn compile

Problem: antlr still not found
Solution: Edit pom.xml and change the antlr version number from 2.9.9 to 2.7.7
Problem: ptalon
	  [INFO] The grammar '/Users/cxh/Documents/workspace/ptII/src/main/antlr/ptolemy/actor/ptalon/parser.g' doesnt exist.
	
Solution: copy the files
	  cd $PTII
	  mkdir -p src/main/antlr/ptolemy/actor/ptalon
	  cp $PTII/ptolemy/actor/ptalon/*.g src/main/antlr/ptolemy/actor/ptalon
	
However, it turned out that none of the files were being copied because $PTII was a symbolic link. See below.
Problem: can't start
	  Exception in thread "main" java.lang.NoClassDefFoundError: ptolemy/vergil/VergilApplication
	
It turns out that the java files were not copied to the right location. $PTII/target/ptII-7.1.devel-SNAPSHOT.jar only contained the antlr classes. The problem was that the toplevel directory where make maven was run was a symbolic link to the actual $PTII directory. The fix was to make sure that in $PTII, $PTII==pwd:
	  bash-3.2$ cd $PTII
	  bash-3.2$ echo $PTII
	  /Users/cxh/ptII
	  bash-3.2$ pwd
	  /Users/cxh/ptII
	
and then to run

	  make maven
	  mvn compile
	
Problem: compilation fails
	  /Users/cxh/Documents/workspace/ptII/src/main/java/ptolemy/moml/jxta/JXTALibrary.java:[44,27] package net.jxta.credential does not exist
	
Solution:
Edit $PTII/pom.xml and uncomment the jxta section
Problem: compilation fails on Eclipse files
	  /Users/cxh/Documents/workspace/ptII/src/main/java/ptolemy/backtrack/eclipse/ast/transform/PackageRule.java:[36,32] package org.eclipse.jdt.core.dom does not exist
	
Proposed Solution: We use the Maven Eclipse Plugin
	    mvn -Declipse.workspace=/Applications/eclipse eclipse:add-maven-repo
	    mvn -DeclipseDir=/Applications/eclipse eclipse:to-maven
	  
However, the problem is telling Maven where to find the Eclipse jars. One idea would be to add dependencies for each jar via configure. However, our workaround is to just not copy the Eclipse plugin files to $PTII/src by running ./configure --without-eclipse.
"mvn package" fails because of backtracking
	  /Users/cxh/ptII/ptolemy/backtrack/eclipse/plugin/editor/PtolemyEditor.java:[52,35] cannot find symbol
	
Solution: disable test-compile:
	    <properties>
	      <!-- skip test-compile when doing "maven package" -->
	      <maven.test.skip>true</maven.test.skip>
	    </properties> 
	  

Maven and Web Start

  1. Install
    	  mvn install webstart:jnlp
    	
has no matching file, why? Check the logs
When running maven webstart:jnlp, I get
	  Embedded error: artifact org.ptolemy:ptII:jar:7.2.devel has no matching file, why? Check the logs...
	
See "3.5.3. Maven Coordinates" of the maven manual, which describes the naming for artifacts. It turns out that the jnlp rule needed to have:
	  <artifactItems>
	  <artifactItem>
	  <groupId>org.ptolemy</groupId>
	  <artifactId>ptII-7.2.devel.jar</artifactId>
	  <version>7.2.devel</version>
	  <type>jar</type>                            
	  </artifactItem>
	  </artifactItems>
	

Maven and OSGI

Bundle Plugin for Maven

Maven Notes