views:

1520

answers:

5

I'm trying to learn JavaFX and maybe create a few "learner" games. I always do my development in Eclipse, rather than NetBeans which the JavaFX team is clearly trying to push.

Can anybody point me in the direction of a how-to for building a JavaFX project in Eclipse, or at least building a JavaFX project without NetBeans? Everything I've found so far either uses NetBeans, or they're running a one-file project in Eclipse (witch won't work for larger projects). Idealy, I'm looking for somebody who's set up a simple Ant script that builds a JavaFX project, since I assume that's the end-game for this situation.

I was able to find where to download the Eclipse JavaFX plugin. It provides syntax highlighting support, plus some "snippets". I can even use it to run simple hello world type JavaFX apps, but I cant seem to get it to automatically build multi-file JavaFX projects. Even if I could, I still can't seem to write a correct ant script to jar up the JavaFX project.

Also, I found this site that talks about what you can do to use a javafxc Ant task created by Sun(?), but I'm not having any luck trying to use what they talk about.

Thanks

Ross

+1  A: 

I have read in article about JavaFX that there is an Eclipse extension available for it. According to that article it is not as mature as NetBeans support for FX but should be better than nothing...

deepc
I tried it with Ganymede and had no luck. I can't really find much information so I don't know if they are looking for help with it.
bmatthews68
I found the project link again. It is http://kenai.com/projects/eplugin
bmatthews68
+3  A: 

If you create new project in NB there is folder called nbproject. This folder contains build-impl.xml. This file contains this target:

<target if="src.dir" name="-compile-fx">
    <taskdef classname="com.sun.tools.javafx.ant.JavaFxAntTask" classpath="${platform.bootcp}" name="javafxc"/>
    <javafxc bootclasspath="${platform.bootcp}" classpath="${build.classes.dir}:${javac.classpath}" compilerclasspath="${platform.bootcp}" debug="${javac.debug}" deprecation="${javac.deprecation}" destdir="${build.classes.dir}" excludes="${excludes}" fork="yes" includeJavaRuntime="false" includeantruntime="false" includes="**/*.fx" source="${javac.source}" sourcepath="" srcdir="${src.dir}" target="${javac.target}">
        <compilerarg line="${javac.compilerargs}"/>
    </javafxc>
</target>

This is good start to create ant for Eclipse. I'm not sure how building works for Eclipse, but there could be limitations. The com.sun.tools.javafx.ant.JavaFxAntTask is located in SDK, not in compiler jar. Good luck!.

Rastislav Komara
A: 

Either use the JavaFxAntTask mentioned before or generate the project in NetBeans and open it in Eclipse and then you can just run Ant targets. Or wait for 1.1 which will hopefully come with full Eclipse and IDEA support.

Honza
+1  A: 

I've created a partial Ant script for the build process. I can tell that it's actually compiling the JavaFX classes and Jaring them up. However, I think I'm missing an Ant task where I create the JNLP object that is needed in the Applet that I'm also missing (but managed to fake).

Since I didn't explicitly state it, I did not get this to a working state, so don't expect to get there just by doing what I did ;)

This Ant script is as far as I've gotten. I've left out everything but the important parts for brevity...

<project name="RABfx" default="all" basedir=".">
    ... 
    <property environment="env"/>
    <property name="java.home" value="${env.JAVA_HOME}" />
    <property name="jfx.home" value="${env.JAVAFX_HOME}" />
    <path id="compile.classpath">
        <fileset dir="${java.home}/lib">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${jfx.home}/lib">
            <include name="**/*.jar" />
        </fileset>
        ...
    </path>

    <taskdef classname="com.sun.tools.javafx.ant.JavaFxAntTask" name="javafxc">
        <classpath refid="compile.classpath" />
    </taskdef>

    ...

    <target name="compile">
        <javac srcdir="${src}" destdir="${src.classes}" includes="**/*.java">
            <classpath refid="compile.classpath" />
        </javac>
        <javafxc srcdir="${src}" destdir="${src.classes}" includes="**/*.fx" executable="${jfx.home}/bin/javafxc.exe">
            <classpath refid="compile.classpath" />
        </javafxc>
        ...
    </target>

    <target name="build">
        <jar jarfile="${src.jar}">
            <fileset dir="${src.classes}" />
        </jar>
    </target>
    ...
</project>

Also, my "faked" Applet...

...
<script src="http://dl.javafx.com/dtfx.js"&gt;&lt;/script&gt;
<script>
    javafx(
        {
            archive: "RABfx.jar",
            width: 440,
            height: 560,
            code: "TicTacToe.Main",
            name: "TicTacToe"
        }
    );
</script>
...
Ross
A: 

After I asked this question, an official (I think?) JavaFX plugin for Eclipse was released. Go to the JavaFX for Eclipse page. I installed the plugin and everything automagically worked!

Ross