commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rosie Chandler <rosie.chand...@btopenworld.com>
Subject Creating jar files using commons-math-1.1
Date Tue, 30 May 2006 11:05:36 GMT
I have a similar problem to before.  I want to create a jar file to use as an extension in
a NetLogo project but I don't know how to set the classpath.  Here is my code:
   
  =========================================
  import org.nlogo.api.*;
import org.apache.commons.math.distribution.*;
import org.apache.commons.math.MathException;
  public class NormsdistExtension extends DefaultClassManager
{
 public void load( PrimitiveManager primManager ) {
  primManager.addPrimitive( "normsdist", new NormsdistClass() );
 }
 
 // NetLogo reporter returns the inverse probit transformation of the inputted number
 public static class NormsdistClass extends DefaultReporter
 {
  // Indicates that the reporter takes one input (either int or float) and has a number output
  public Syntax getSyntax() 
  {
   int[] input = new int[] {Syntax.TYPE_NUMBER};
   return Syntax.reporterSyntax(input, Syntax.TYPE_NUMBER) ;
  }
    // Reporter code
  public Object report(Argument args[], Context context) throws ExtensionException 
  {
     // This is the first input argument, and it's a float
   double inputArgument = args[0].getDoubleValue();
     DistributionFactory factory = DistributionFactory.newInstance();
   NormalDistribution NormDistn = factory.createNormalDistribution();
   Double outputValue = 0.0;
     try
   {
    outputValue = NormDistn.cumulativeProbability(inputArgument);
   }
   catch (MathException me)
   {
    System.err.println(me.getMessage());
    System.exit(1);
   }
     return outputValue;
  }
 }
}
====================================
   
  I compile the code with:
   
  javac -classpath NetLogo.jar;commons-math-1.1.jar;. NormsdistExtension.java
   
  If I was writing an extension that didn't include the commons-math library I would create
the jar file using:
   
  jar cvfm Normsdist.jar manifest.txt NormsdistExtension$testExtension.class NormsdistExtension.class
   
  Except that when I attempt to use the Normsdist.jar file as an extension in my NetLogo project
I again get the error reported that the commons-library classes can't be found.  How can I
add the commons-math-1.1.jar to the classpath when I'm creating a jar file?  If I was just
running the code I would use something like:
   
  java -classpath NetLogo.jar;commons-math-1.1.jar;. NormsdistExtension
   
  And this works fine, but I don't seem to be able to use the classpath command when I try
to create the jar file...

Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message