Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX 2.0 + NetBeans + Maven

I am creating JavaFX 2.0 application using NetBeans 7.0.1. When I create project in standard way everything works fine. Unfortunately ;) I need Maven project...

I didn't find JavaFX 2.0 in Maven repository, so my pom.xml right now looks like this:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mygroup</groupId>
    <artifactId>ui</artifactId>
    <version>0.1</version>
    <name>My Project</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javafx</groupId>
            <artifactId>jfxrt</artifactId>
            <version>2.0</version>
            <type>jar</type>
            <scope>system</scope>
            <systemPath>${env.JAVAFX_HOME}\lib\jfxrt.jar</systemPath>
        </dependency>
    </dependencies>
</project>

JAVAFX_HOME system variable is set:

C:\Users\rach>echo %JAVAFX_HOME%
C:\Program Files\Oracle\JavaFX Runtime 2.0\

Compilation goes okay, but when I start program under NetBeans I got error:

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application at java.lang.ClassLoader.defineClass1(Native Method)

However jfxrt.jar is in classpath:

C:\>echo %CLASSPATH%
C:\Program Files\Oracle\JavaFX Runtime 2.0\lib\jfxrt.jar

When I start my application from command line it works fine.

When I install jfxrt.jar in local repository at runtime application still does not start because it cannot find C:\Program Files\Oracle\JavaFX Runtime 2.0\bin\mat.dll. Pom.xml:

<dependency>
    <groupId>javafx</groupId>
    <artifactId>jfxrt</artifactId>
    <version>2.0</version>
    <type>jar</type>
</dependency>

Effect:

Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Repositories\MavenRepo\javafx\jfxrt\bin\mat.dll at com.sun.javafx.tk.quantum.QuantumToolkit.startup(Unknown Source)

Any ideas?

like image 564
Rafal Avatar asked Aug 18 '11 10:08

Rafal


3 Answers

Thank you for your help.

Those who are using JavaFX 2.0 SDK here are simple steps

  1. Go to JavaFX 2.0 SDK\rt\lib in your shell (command prompt)

  2. Execute mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx -Dpackaging=jar -Dversion=2.0

  3. Copy bin folder from your JavaFX 2.0 SDK\rt\ directory to your .m2\repository\com\oracle\javafx directory

4.<dependency>
<groupId>com.oracle</groupId> <artifactId>javafx</artifactId> <version>2.0</version> <scope>compile</scope> </dependency>

like image 135
Sarad Thapa Avatar answered Oct 26 '22 18:10

Sarad Thapa


The best answer for current Java 7, with bundled Java FX 2.0, is:

<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>javafx</artifactId>
  <version>2</version>
  <systemPath>${java.home}/lib/jfxrt.jar</systemPath>
  <scope>system</scope>
</dependency>    

and add this to the "Run Project" Action of the used Maven profile in NetBeans:

exec.classpathScope=compile

You can also use this with the "Debug project", "Profile Project", "Run file via main()", "Debug file via main()", and "Profile file via main()" actions :)

like image 20
Infernoz Avatar answered Oct 26 '22 17:10

Infernoz


For now, this seems to be a solution that works..

First, install the jfxrt.jar:

mvn install:install-file -Dfile=jfxrt.jar -DgroupId=com.oracle -DartifactId=javafx-runtime -Dpackaging=jar -Dversion=2.0

Then copy the bin folder from your downloaded JavaFX runtime into your local Maven repo (home/.m2/repository/com/oracle/javafx-runtime/)

Not very elegant, but it works for me..

like image 20
Kristian Avatar answered Oct 26 '22 18:10

Kristian