我试图从rake中使用JavaFX的ant任务,但无法弄清楚如何处理xml-namespacing:http://ant.apache.org/manual/Types/namespace.html

一个做类似工作的build.xml文件看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorldApp" default="default" basedir="."
         xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <path id="fxant">
      <filelist>
        <file name="${java.home}\..\lib\ant-javafx.jar"/>
        <file name="${java.home}\lib\jfxrt.jar"/>
      </filelist>
    </path>
    <target name="default">
        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${java.home}\..\lib\ant-javafx.jar"/>
    </target>
<target name="package-bundle">
      <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${java.home}\..\lib\ant-javafx.jar"/>
      <fx:deploy nativeBundles="all"
                   width="100" height="100"
                   outdir="build/" outfile="HelloWorldApp">
            <info title="Hello World App" vendor="Me"
                     description="Test built from Java executable jar"/>
            <fx:application mainClass="org.jruby.JarBootstrapMain"/>
            <fx:resources>
               <fx:fileset dir="dist">
                  <include name="HelloWorldApp.jar"/>
               </fx:fileset>
            </fx:resources>
      </fx:deploy>
</target>
</project>

问题出在诸如“fx:deploy”之类的任务上,当我开始将其转换为Rakefile时,我走得太远,因为我不知道如何向 Ant 介绍该“fx”命名空间。我已经搜索了几天,但是我发现的只是headius的一篇博客文章,上面写着“自我注释:弄清楚我们是否对此具有相同的含义”(http://headius.blogspot.com/2010/04/using-ivy-with-jruby-15s-ant.html)。在他的示例中,他似乎能够忽略它,但是在这种情况下不起作用。

JavaFX打包任务提供了一些非常酷的东西,尤其是从Java 8开始,包括能够从任何可执行jar为每个平台创建 native 安装程序的功能。我认为这可能真的有用。

最佳答案

好的,所以我们缺少一些魔术,但是我没有变通的方法。要调用XML命名空间任务,您需要发送到完全合格的xml uri。这有点丑陋,但并不像以前那样丑陋,因为只有顶级父级才需要执行此hack,并且子级合格元素相对于父级才是相对的,因此他们也不需要发送。我为此here添加了一个增强问题:

require 'ant'

task :default do
  ant.echo message: "${java.home}"
  ant.taskdef(resource: "com/sun/javafx/tools/ant/antlib.xml",
              uri: "javafx:com.sun.javafx.tools.ant",
              classpath: "${java.home}/../lib/ant-javafx.jar")
end

task :package_bundle do
  ant do
    taskdef(resource: "com/sun/javafx/tools/ant/antlib.xml",
            uri: "javafx:com.sun.javafx.tools.ant",
            classpath: "${java.home}/../lib/ant-javafx.jar")
    __send__("javafx:com.sun.javafx.tools.ant:deploy", nativeBundles: "all",
             width: "100", height: "100", outdir: "build/",
             outfile: "HelloWorldApp") do
      info(title: "Hello World App", vendor: "Me",
           description: "Test built from Java executable jar")
      application(mainClass: "org.jruby.JarBootstrapMain")
      resources do
        fileset(dir: "dist") do
          include name: "HelloWorldApp.jar"
        end
      end
    end
  end
end

10-08 01:23