You can build your JavaFX sources with Maven 2 using standard “maven-compiler-plugin”.
Put something similar in <build>
section of POM
file:
<build> <sourceDirectory>src/main/fx</sourceDirectory> ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerId>javafxc</compilerId> <include>**/*.fx</include> </configuration> <dependencies> <dependency> <groupId>net.sf.m2javafxc</groupId> <artifactId>plexus-compiler-javafxc</artifactId> <version>0.1-SNAPSHOT</version> </dependency> </dependencies> </plugin> </plugins> ... </build>
Add m2-javafxc repository to <pluginRepositories>:
<pluginRepositories> <pluginRepository> <id>m2-javafxc</id> <name>Sourceforge M2-javafxc static repo</name> <url>http://m2-javafxc.sourceforge.net/m2repo</url> </pluginRepository> </pluginRepositories>
Make sure you have $JFX_HOME environment variable set.
Add dependency to javafxrt.jar :
<dependency> <groupId>net.java.dev.openjfx</groupId> <artifactId>javafxrt</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
For compiling it is enough, but to compile with UI or/and to run (even simple CLI JavaFX application) you should have dependency to scenario.jar:
<dependency> <groupId>net.java.dev.openjfx</groupId> <artifactId>scenario</artifactId> <version>0.6-SNAPSHOT</version> </dependency>
Currently there is no one public repository you could get javafxrt and scenario from, so there is 3 ways to get it in your local repo:
Manually download and install artifacts, like this mvn install:install-file -Dversion=1.0-SNAPSHOT -Dpackaging=jar -DgroupId=net.java.dev.openjfx -Dartifacthttp://maven.apache.org/plugins/maven-install-plugin/examples/installing-checksums.htmlId=javafxrt -Dfile=$(echo "$JFX_HOME/lib/"javafxrt*.jar)
Use <scope>system</scope>
in <dependency>
and specify <systemPath>
Check out from SVN: https://m2-javafxc.svn.sourceforge.net/svnroot/m2-javafxc/openjfx2maven project and run build.xml. It will automatically download weekly build from OpenJFX-Compiler development site and install into your local repository. NOTE: you should have ANT 1.7.0, ANT Task for Maven 2 2.0.8 installed to run this script. We plan to have this build.xml file weekly updated. So that once you get it working you could no longer worry about installation of latest artifacts – it will be done with one click. Also you could install to local repo all previous versions of artifacts.
Yes, you may run javafxc as a sub process, just specify
<fork>
in config:
<configuration> <compilerId>javafxc</compilerId> <include>**/*.fx</include> <fork>true</fork> </configuration>
It is possible to specify location of javafx.jar directly in the POM (javafxc.jar will be looked up in the C:/jfx first):
<configuration> <fork>false</fork> <compilerArguments> <jfxHome>C:/jfx</jfxHome> </compilerArguments> </configuration>
It is possible to run exact version of javafxc.jar as artifact (if you have it installed somewhere in Maven2 or local repo):
<configuration> <fork>false</fork> <compilerArguments> <jfxHome>false</jfxHome> </compilerArguments> </configuration>
and add javafxc.jar for plugin runtime dependencies:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerId>javafxc</compilerId> <include>**/*.fx</include> <fork>false</fork> <compilerArguments> <jfxHome>false</jfxHome> </compilerArguments> </configuration> <dependencies> <dependency> <groupId>net.sf.m2javafxc</groupId> <artifactId>plexus-compiler-javafxc</artifactId> <version>0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>net.java.dev.openjfx</groupId> <artifactId>javafxc</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </plugin>
Sometimes it is hard to understand where the real javafxc.jar comes from... Use -X and -e option to understand what jar file in use.
If you have any suggestions, ideas or want to contribute, mail list is: m2-javafxc-develop@lists.sourceforge.net (archive http://sourceforge.net/mailarchive/forum.php?forum_name=m2-javafxc-develop). Thank you!
Happy coding! :)