Javafx ant task


(John Scancella) #1

Hello,

I am trying to use the javafx ant tasks but I don’t know how to reference it in my build script. I tried to copy How do I use ant xmlns in gradle? but I keep getting

Problem: failed to create task or type fx.com.sun.javafx.tools.ant:jar Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any <presetdef>/<macrodef> declarations have taken place. No types or tasks have been defined in this namespace yet

the task looks like this:

task foo << {
def javaHome = System.getProperty("java.home")
def javaFxAntLib = javaHome + "/../lib/ant-javafx.jar"
``
ant.taskdef( resource:"com/sun/javafx/tools/ant/antlib.xml", classpath: javaFxAntLib, uri: 'javafx:com.sun.javafx.tools.ant')
ant.'javafx.com.sun.javafx.tools.ant:jar:jar' (destfile: 'myApp.jar')
}

sorry about the formatting, I tried for like 20 minutes to get it right. I wish you guys used something like github’s markup instead.


(Stefan Oehme) #2

We do, just use triple ticks ``` like on Github.

Looks like a typo - one too many :jar.


(John Scancella) #3

good to know on the triple ` like github. The preformatted button only does inline code

after fixing the task:

task foo << {
  def javaHome = System.getProperty("java.home")
  def javaFxAntLib = javaHome + "/../lib/ant-javafx.jar"
  
  ant.taskdef( resource:"com/sun/javafx/tools/ant/antlib.xml", classpath: javaFxAntLib, uri: 'javafx:com.sun.javafx.tools.ant')
  ant.'javafx.com.sun.javafx.tools.ant:jar' (destfile: 'myApp.jar')
  }

it still has an error:

Execution failed for task ':foo'.
> Problem: failed to create task or type javafx.com.sun.javafx.tools.ant:jar
  Cause: The name is undefined.
  Action: Check the spelling.
  Action: Check that any custom tasks/types have been declared.
  Action: Check that any <presetdef>/<macrodef> declarations have taken place.
  No types or tasks have been defined in this namespace yet

(John Scancella) #4

For those of you that are having the same problem I think I figured it out. You need to put a colon between javafx and the ant namespace (previously I put a dot).

The task looks like:

task foo << {
  def javaHome = System.getProperty("java.home")
  def javaFxAntLib = javaHome + "/../lib/ant-javafx.jar"
  
  ant.taskdef( resource:"com/sun/javafx/tools/ant/antlib.xml", classpath: javaFxAntLib, uri: 'javafx:com.sun.javafx.tools.ant')
  ant.'javafx:com.sun.javafx.tools.ant:jar' (destfile: 'myApp.jar'){
    fileset(dir: 'build/classes/main')
    application(name:"JavaFXHelloWorldApp", mainClass:"HelloWorld")
  }
}

(Purring Pigeon) #5

Check out this plugin https://github.com/FibreFoX/javafx-gradle-plugin it’s great.