Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Using JavaScript in Ant




I am having issues using the <script> tag in Ant and I am hoping someone can help. I want to use JavaScript in my Ant build.xml. Something like the following:

<?xml version="1.0" encoding="UTF-8"?>
<project name="java" default="main" basedir=".">
  <target name="main">
    <script language="javascript"> <![CDATA[
 println("hello, world")
    ]]> </script>

Unfortunately this only displays and error:

build.xml:4: Could not create task or type of type: script.

I have located the required jar file (js.jar) for this to work and moved it to ANT_HOME/lib, but I am still stuck as of how to get this to work.

like image 244
ah414 Avatar asked Mar 24 '23 07:03


1 Answers

In addition to js.jar, you need to add bsf.jar and commons-logging-*.jar to ANT_HOME/lib. In your Ant distribution, there is a file named docs/manual/install.html. The Library Dependencies section of this HTML file documents where you can download these files.

println isn't supported in JavaScript. Instead, use the following:

<project name="jsTest" default="main">
  <target name="main">
    <script language="javascript"> <![CDATA[
        var echo = jsTest.createTask("echo");
        echo.setMessage("hello, world");
    ]]> </script>
like image 100
Chad Nouis Avatar answered Apr 02 '23 09:04

Chad Nouis