在Jruby Rake的Ant集成中,处理ant的xml名称空间支持的策略

Edu*_*ndo 5 ant rake jruby

我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

问题出现在像"fx:deploy"这样的任务中,当我开始将它转换为Rakefile时,我无法走远,因为我无法弄清楚如何告诉ant关于那个"fx"命名空间.我已经搜索了几天,但我发现的所有内容都是来自headius的一篇博文,上面写着"自我注意:弄明白我们是否有相同的东西"(http://headius.blogspot.com /2010/04/using-ivy-with-jruby-15s-ant.html).在他的例子中,他似乎能够忽略它,但在这种情况下这不起作用.

JavaFX打包任务提供了一些非常酷的东西,特别是从Java 8开始,包括从任何可执行jar为每个平台创建本机安装程序的能力.我认为这可能非常有用.

小智 2

好吧,我们错过了一些魔法,但一切并没有失去,我有一个解决方法。要调用 XML 命名空间任务,您需要发送到完全限定的 xml uri。这有点丑陋,但并不那么丑陋,因为只有顶级父级需要执行此操作,而子级合格元素是相对于其父级的,因此它们不需要执行发送。我在这里添加了一个增强问题:

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
Run Code Online (Sandbox Code Playgroud)