---
title: "Ant - scriptdef - Unable to create javax script engine for javascript"
author: "aryanwang"
date: "2012-02-23T12:02:13Z"
tags: []
categories: ["研发管理"]
slug: "ant-scriptdef-unable-to-create-javax-script-engine-for-javascript"
draft: false
lastmod: "2012-02-23T12:02:13Z"
id: 1420014
url: "https://keepmoving2012.iteye.com/blog/1420014"
---

Ref : [http://ant.apache.org/manual/Tasks/scriptdef.html](http://ant.apache.org/manual/Tasks/scriptdef.html)

 

在Ant里可以用scriptdef标签来定义一段脚本成为一个任务，今天用JavaScript和该标签定义了一个任务，将字符串转小写，代码如下：

 

```
<scriptdef name="lc" language="javascript">
        <attribute name="property"/>
        <attribute name="value"/>
        project.setNewProperty(attributes.get("property"),
        attributes.get("value").toLowerCase());
</scriptdef>
```

 

调用代码如下：

 

```
<lc property="test.property" value="XXXXXXXXXX" />
<echo message="${test.property}"/>
```

 

 

 这时将打印小写的X字符串。

 

如果脚本类型是JavaScript， 则需要以下添加第三方依赖包：

 

          **Jar** **下载地址** js.jar [http://www.mozilla.org/rhino/download.html](http://www.mozilla.org/rhino/download.html) bsf.jar [http://commons.apache.org/bsf/download\_bsf.cgi](http://commons.apache.org/bsf/download_bsf.cgi) commons-logging.jar [http://commons.apache.org/logging/download\_logging.cgi](http://commons.apache.org/logging/download_logging.cgi)