How can I run perl and ruby scripts as tasks in an

2019-02-18 20:54发布

问题:

I would like to be able to run ruby and perl scripts from build.xml in ant.

回答1:

You can always use the ant`s exec task to run arbitrary programs, such as ruby and perl. For example and from the docs:

<target name="help">
  <exec executable="cmd">
    <arg value="/c"/>
    <arg value="ant.bat"/>
    <arg value="-p"/>
  </exec>
</target>


回答2:

Languages like Ruby have Java implementations.

<project name="RunRubyExample">
    <property environment="env" />
    <script language="ruby" manager="bsf">
        <classpath>
            <fileset dir="${env.JRUBY_HOME}/lib" includes="*.jar" />
        </classpath>

        print 'hello world'

    </script>
</project>

See the list of languages supporting the JSR233 standard.

Unfortunately no Java version of Perl is available. The only way to run Perl scripts is to invoke the interpreter directly:

<project name="RunPerlExample">
    <exec executable="perl" failonerror="true">
        <arg value="-e" />
        <arg value="print 'hello world'" />
    </exec>
</project>


标签: ruby perl ant