Discussion:
running a JavaFX maven project
carljmosca
2012-07-20 19:29:10 UTC
Permalink
I have been working with a JavaFX project in NetBeans. The project is in maven format and utilizes the javafxpackager. It is a combination of a few examples I have been able to find on the web.

When I run the program from within NetBeans I get an error which I believe indicates the JavaFX runtime jar is not available:

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application

I have tried changing the outputDirectory of the jar files. I was under the impression that this is a JavaFX/maven issue but I now think it's a NetBeans problem (or a problem with how I have configured a NB project). In the current state, the jar files are copied to the target directory (instead of the default target/dependency directory).

I am able to run this project via the command line:

java -jar JFXMavenPkgExample.jar (from the target directory)

I have tried changing the parameters on the run action to include the classpath (before and after I changed the outputDirectory in the configuration of the maven-dependency-plugin) but so far I have not had success.

The project is now on github: https://github.com/carljmosca/JFXMavenPkgExample

because I would like to share a complete working example once I get there. :)

TIA,
Carl
Fabrizio Giudici
2012-07-20 19:57:52 UTC
Permalink
Post by carljmosca
I have been working with a JavaFX project in NetBeans. The project is
in maven format and utilizes the javafxpackager. It is a combination of
a few examples I have been able to find on the web.
When I run the program from within NetBeans I get an error which I
javafx/application/Application
I have tried changing the outputDirectory of the jar files. I was under
the impression that this is a JavaFX/maven issue but I now think it's a
NetBeans problem (or a problem with how I have configured a NB
project). In the current state, the jar files are copied to the target
directory (instead of the default target/dependency directory).
Do you mean target/deploy?

I checked out and tried your project (with JDK 7 on MAc OS X; I had to
remove the nativeBundles="all" option and commented out the signing stuff.
I can run it with the command line. By using the "Run" menu in NetBeans I
get the error below. Is it what you're seeing?






cd /private/tmp/X1/JFXMavenPkgExample;
JAVA_HOME=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
/Users/fritz/Applications/apache-maven-3.0.4/bin/mvn
"-Dexec.args=-classpath %classpath com.github.jfxmavenpkgexample.App"
-Dexec.executable=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java
-Dexec.classpathScope=runtime -Dexec.workingdir= -DskipTests=true
process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec
SETTINGS: default-settings.xml
Scanning for projects...
Downloading:
http://hudson.tidalwave.it/nexus/content/groups/public/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.pom

Downloaded:
http://hudson.tidalwave.it/nexus/content/groups/public/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.pom
(7 KB at 5.6 KB/sec)
Downloading:
http://hudson.tidalwave.it/nexus/content/groups/public/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.jar

Downloaded:
http://hudson.tidalwave.it/nexus/content/groups/public/org/codehaus/mojo/exec-maven-plugin/1.2/exec-maven-plugin-1.2.jar
(36 KB at 60.8 KB/sec)

------------------------------------------------------------------------
Building JFXMavenPkgExample 1.0-SNAPSHOT
------------------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.893s
Finished at: Fri Jul 20 21:53:32 CEST 2012
Final Memory: 6M/106M
------------------------------------------------------------------------
Unknown lifecycle phase "%classpath". You must specify a valid lifecycle
phase or a goal in the format <plugin-prefix>:<goal> or
<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.
Available lifecycle phases are: validate, initialize, generate-sources,
process-sources, generate-resources, process-resources, compile,
process-classes, generate-test-sources, process-test-sources,
generate-test-resources, process-test-resources, test-compile,
process-test-classes, test, prepare-package, package,
pre-integration-test, integration-test, post-integration-test, verify,
install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean,
post-clean. -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read
the following articles:
[Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
***@tidalwave.it
http://tidalwave.it - http://fabriziogiudici.it
carljmosca
2012-07-20 20:18:00 UTC
Permalink
Ah, I did forget to mention that there should be a file named javafx.ks in a "keystore" directory in the home directory.

Sorry about that...I will update the README.

This project, or one very similar to it because I have been modifying it today, builds on a Linux-hosted Jenkins server and on my Mac running Java 1.7.0_06.

I can do a clean/build from NetBeans (using maven 3) with no errors and then run it from the command line as I explained above. [It even builds the package; sweet the first time you see it. :) ]

The error I get is when I do a run from NB.
run:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelJava Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
Fabrizio Giudici
2012-07-20 20:36:41 UTC
Permalink
Post by carljmosca
Ah, I did forget to mention that there should be a file named javafx.ks
in a "keystore" directory in the home directory.
Sorry about that...I will update the README.
This project, or one very similar to it because I have been modifying it
today, builds on a Linux-hosted Jenkins server and on my Mac running
Java 1.7.0_06.
I can do a clean/build from NetBeans (using maven 3) with no errors and
then run it from the command line as I explained above. [It even builds
the package; sweet the first time you see it. :) ]
The error I get is when I do a run from NB.
javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelJava Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
So it's different from what I'm seeing. I see an error, but a different
error. Pretty strange.
--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
***@tidalwave.it
http://tidalwave.it - http://fabriziogiudici.it
carljmosca
2012-07-21 17:10:36 UTC
Permalink
So first I suspected maven was the issue but when I realize I could easily run the project from the command line, I thought NetBeans was the cause.

The solution, at least in my case, was to make the JavaFX runtime available to the system via the extensions directory.

I will update the project with details.

Thank you,
Carl

Loading...