JavaFX and Maven

There is a post which discusses all the details about how to set up JavaFX in a maven project (compiling etc).

For my timefinder project I only need a solution where I can use a JavaFX-jar within my maven project. This is a little bit faster to achieve:

  1. First, be sure you set up JavaFX correctly. For linux and JavaFX 1.1 you can try this.
  2. Now write the following in your /home/user/.m2/settings.xml:
    <settings>
      <profiles>
        <profile>
          <id>test</id>
          <activation>
            <property>
                    <name>!javafx_home</name>
            </property>
          </activation>
            <properties>
                <!-- linux -->
                    <javafx_home>/home/user/programs/netbeans-6.5/javafx2/javafx-sdk1.0</javafx_home>
                <!-- windows
                    <javafx_home>C:\Program Files\NetBeans 6.5\javafx2\javafx-sdk</javafx_home> -->
            </properties>
         </profile>
      </profiles>
      ...
    </settings>
  3. After this you can include the javafx libraries in your pom.xml:
    <project>
      ...
      <dependencies>
           ...
            <dependency>
                <groupId>com.sun.javafx.rt15</groupId>
                <artifactId>javafx-rt15</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/rt15.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.gui</groupId>
                <artifactId>javafx-gui</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/javafxgui.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.rt</groupId>
                <artifactId>javafx-rt</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/shared/javafxrt.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.eula</groupId>
                <artifactId>javafx-eula</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/eula.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.scenario</groupId>
                <artifactId>javafx-scenario</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/Scenario.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.swing</groupId>
                <artifactId>javafx-swing</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/javafx-swing.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.jmc</groupId>
                <artifactId>javafx-jmc</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/jmc.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.websvc</groupId>
                <artifactId>javafx-websvc</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/websvc.jar</systemPath>
            </dependency>
            <dependency>
                <groupId>com.sun.javafx.scriptapi</groupId>
                <artifactId>javafx-scriptapi</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${javafx_home}/lib/desktop/script-api.jar</systemPath>
            </dependency>
            <!-- The javafx dependencies are taken from the profiles/desktop.properties file-->
        </dependencies>
    </project>
  4. That’s it! Now you should be able to use javafx or javafx-components in you fancy application. In the most cases you might be interested in one of my previous posts, which discusses how to embed a javafx-component into an existing Swing-application.

NetBeans = Best Maven IDE?

Today I want show what is possible with Maven 2.0.9 in NetBeans 6.5 and what makes me nervous.

First of all you have to download NetBeans and then the Maven plugin: Click Tools->Plugins->Available Plugins.

I recommend to install the command line of maven and then set the ‘connection’ to the local repository in NetBeans: Tools->Options->Miscellaneous->Maven->Local Repository should be sth. like /home/user/.m2/repository

  • Add a new jar to the project via right click or directly in the pom.xml: there you will have code completion! I.e. you can always choose the latest version of a library or easily switch versions.
  • Add javadoc or sources (download all source)

    add-sources-and-javadoc

    download-sources

  • You can search unknown class in repository

    search-unknown-symbol

    search-in-repositories

    after adding the JodaTime library with this dialog and adding the sources with the first dialog – all is fine:

    auto-added-lib

  • Set different goal to F6: right click the project->properties->actions->run project and then clear all the fields and set the ‘execute goal’ e.g. to
    mvn jetty:run
  • In the same dialog you can set skip test to true if this is necessary or if you want to speed up compilation
  • Profiling and debugging of a maven project works now, although I had some problems under vista with profiling, but under linux were no issues

So I am nearly happen with maven under NetBeans, but what really sucks is maven while compiling. A small native NetBeans project takes under 2 seconds to clean and compile. And with maven? Nearly 10 seconds!
How could one change this? I only found a workaround to use the same project as native NetBeans project, but nothing more. Any ideas how to make ‘maven install’ or ‘mvn compile’ faster??

(BTW: Today wordpress does not want that I make clickable images … if you want to see the images in better quality you have to right click them->view->remove the stuff after ‘?’. Example: https://karussell.files.wordpress.com/2009/02/add-sources-and-javadoc.jpg)

Maven2. Phases vs. Goals

What is the difference between phases and goals in maven?

I would like to explain the difference with an example:

Imagine you need an ant task (like copying files) and you want to do this task on every call of

mvn install

For this it is necessary to bind the goal ‘run’ from the maven-ant plugin to the phase ‘install’ of the maven lifecycle:

<build>
   <plugins>
     <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
             <phase>install</phase>
             <configuration>
                <tasks>
                    <copy file="fromfile" todir="todirectory" />
                </tasks>
             </configuration>
             <goals>
                 <goal>run</goal>
             </goals>
          </execution>
        </executions>
    </plugin>
   </plugins>
</build>