Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
random number generator

random number generator

2007-07-21       - By Mario Madunic
Reply:     1     2     3  


Hi,

I'm trying to generate a random number to be used as a temporary directory name
through a multi step xslt process. I'm using Ant 1.6.5 and Java 1.6.0-b105

I've placed the following .jars into Ant/lib
js.jar
bsh-2.0b4.jar
commons-httpclient-3.1-rc1.jar
commons-logging-1.1.jar
commons-logging-adapters-1.1.jar
commons-logging-api-1.1.jar
bsf.jar

I've tracked down the following and can't seem to get it working. Any help with
this would be appreciated

<scriptdef language="javascript" name="random">
<attribute name="max"/>
<attribute name="property"/>
var max=attributes.get("max")
var property=attributes.get("property")
if(max==null || property==null) {
self.fail("'property' or 'max' is not set")
} else {
var result=java.util.Random().nextInt(max)
self.log("Generated random number " + result)
project.setNewProperty(property, result);
}
</scriptdef>

<random max="20" property="result"/>
<echo>Random number is ${result}</echo>


I receive the following error

  [random] Jul 20, 2007 9:11:27 PM org.apache.bsf.BSFManager exec
  [random] SEVERE: Exception :
  [random] java.security.PrivilegedActionException:
org.apache.bsf.BSFException: JavaScript Error: Internal Error:
org.mozilla.javascript.EcmaError: ReferenceError: "self" is not defined.
  [random]     at java.security.AccessController.doPrivileged(Native Method)
  [random]     at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
  [random]     at
org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.java:128)
  [random]     at
org.apache.tools.ant.taskdefs.optional.script.ScriptDef.executeScript(ScriptDef
.java:317)
  [random]     at
org.apache.tools.ant.taskdefs.optional.script.ScriptDefBase.execute
(ScriptDefBase.java:47)
  [random]     at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
  [random]     at org.apache.tools.ant.Task.perform(Task.java:364)
  [random]     at org.apache.tools.ant.Target.execute(Target.java:341)
  [random]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
  [random]     at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
  [random]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
  [random]     at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java
:40)
  [random]     at org.apache.tools.ant.Project.executeTargets(Project.java
:1068)
  [random]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
  [random]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
  [random]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
  [random]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
  [random] Caused by: org.apache.bsf.BSFException: JavaScript Error: Internal
Error: org.mozilla.javascript.EcmaError: ReferenceError: "self" is not defined.
  [random]     at
org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(JavaScriptEngine
.java:195)
  [random]     at
org.apache.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java
:147)
  [random]     at org.apache.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java
:141)
  [random]     at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
  [random]     ... 17 more

Thanks

Mario M

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.