Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“蚂蚁产量”中的Beanshell;无法为beanshell创建javax脚本引擎;_Java_Ant_Beanshell - Fatal编程技术网

“蚂蚁产量”中的Beanshell;无法为beanshell创建javax脚本引擎;

“蚂蚁产量”中的Beanshell;无法为beanshell创建javax脚本引擎;,java,ant,beanshell,Java,Ant,Beanshell,您好,我正在尝试在Ant build.xml文件中放入一些Beanshell脚本。我已经尽我所能地遵循了Ant手册,但当我运行Ant时,我一直感到“无法为beanshell创建javax脚本引擎”。以下是我主要根据Ant手册中的示例编写的测试目标: <target name="test-target"> <script language="beanshell" setbeans="true"> <classpath>

您好,我正在尝试在Ant build.xml文件中放入一些Beanshell脚本。我已经尽我所能地遵循了Ant手册,但当我运行Ant时,我一直感到“无法为beanshell创建javax脚本引擎”。以下是我主要根据Ant手册中的示例编写的测试目标:

<target name="test-target">
    <script language="beanshell" setbeans="true">
        <classpath>
            <fileset dir="c:\TEMP" includes="*.jar" />
        </classpath>
        System.out.println("Hello world");
    </script>
</target>

System.out.println(“你好世界”);
我的beanshell“bsh-2.0b4.jar”文件位于脚本任务的类路径上,与手册推荐的方式相同。希望我有正确的档案。我现在在c:\TEMP工作。
我已经在谷歌上搜索和尝试了一段时间。任何想法都将不胜感激。谢谢。

首先,您需要从这里获得jsr-engines.zip:

在里面,您可以找到jsr223/beanshell/build/bsh-engine.jar。一些搜索暗示您需要下载bsh-2.05b.jar。我在这里找到的:

更容易找到的bsh-2.0b4.jar似乎也能工作,但它打印了一条消息,暗示它是实验性的。

Ant插件“org.apache.Ant_1.7.0.v200803061910”具有当前(2012年)所需的所有jar文件。您只需1个jar即可启动BeanShell的脚本任务:

在此之前,我还想到了以下内容,正如Ant手册所提到的:

但是,至少在我的环境中,
bsh
似乎不需要
bsf

一旦jar被提供给ant,脚本任务就会顺利运行。有两种可能的场景可以获取jar并将其提供给ant

手动下载方式 下载上面的jar。我提供了来自maven存储库的链接。下载完所有JAR后,将其提供给ant。有 至少有3种方法可以做到这一点:

  • 将它放在java库路径中
  • 把它放在ant库目录中
  • script
    任务提供正确的类路径
  • 我发现最后一种方法是最好的,因为它最容易在两种方法之间移植 不同的系统。脚本任务的ant文件可能如下所示:

    <project default="t1" >
      <property name="bsh.path"
        location="/mnt/q/jarek/lang/java/ant/stackoverflow/bsh-2.0b5.jar" />
      <target name="t1">
        <script language="beanshell" classpath="${bsh.path}">
          javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
        </script>
      </target>
    </project>
    
    ivy.xml

    <project default="t1"
             xmlns:ivy="antlib:org.apache.ivy.ant" >
    
      <property name="ivy.install.version" value="2.2.0" />
      <property environment="env" />
      <condition property="ivy.home" value="${env.IVY_HOME}">
        <isset property="env.IVY_HOME" />
      </condition>
      <property name="ivy.home" value="${user.home}/.ant" />
      <property name="ivy.jar.dir" value="${ivy.home}/lib" />
      <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
    
      <target name="check-ivy">
        <condition property="ivy.present">
          <available file="${ivy.jar.file}" type="file" />
        </condition>
      </target>
    
      <target name="download-ivy" unless="ivy.present">
          <mkdir dir="${ivy.jar.dir}"/>
          <!-- download Ivy from web site so that it can be used even without any special installation -->
          <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" 
               dest="${ivy.jar.file}" usetimestamp="true"/>
      </target>
    
      <target name="init-ivy" depends="check-ivy, download-ivy">
        <!-- try to load ivy here from ivy home, in case the user has not already dropped
                it into ant's lib dir (note that the latter copy will always take precedence).
                We will not fail as long as local lib dir exists (it may be empty) and
                ivy is in at least one of ant's lib dir or the local lib dir. -->
          <path id="ivy.lib.path">
              <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
          </path>
          <taskdef resource="org/apache/ivy/ant/antlib.xml"
                   uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
      </target>
    
      <target name="ivy-libs" depends="init-ivy" >
        <ivy:cachepath pathid="path.from.ivy" log="download-only" />
      </target>
    
      <target name="t1" depends="ivy-libs" >
        <script language="beanshell" classpathref="path.from.ivy">
          javax.swing.JOptionPane.showMessageDialog(null, "Hello, Script!");
        </script>
      </target>
    
    </project>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ivy-module version="2.0" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation=
                       "http://ant.apache.org/ivy/schemas/ivy.xsd">
    
    <info organisation="example.com" module="testing-script-task" /> 
    
    <dependencies>
      <dependency org="org.beanshell" name="bsh" rev="2.0b5" />
      <!--  <dependency org="bsf" name="bsf" rev="2.4.0" /> -->
    </dependencies>
    
    </ivy-module>
    

    不要使用
    beanshell
    语言。改用
    javascript
    ,因为它在jdk6上运行,没有任何额外的jar。他告诉我的


    Javascript
    也允许使用java类,例如
    java.lang.System.out.println()

    啊,这很有效!非常感谢。我将这两个文件都包含在任务的类路径中,它成功了。我很好奇你是怎么发现b5版本的。也许这是一个开发版本。谷歌上有很多搜索。我得到的印象是beanshell已经被放弃了。第一个链接被破坏了,尽管我在这里找到了它:BSF被“放弃”的原因是它已经成为JSR233(Java平台脚本)的一个实现。BSF背后的想法在Java平台规范中被吸收,因为它变得非常有用。如果它现在是Java平台的一部分,如何在ANT中使用该功能?