Javafx app in maven project

I have a project with a structure like this:

main project
-libary-1
-library-2
-i-need-javafx-application-here

So, I need a JavaFX 2 application in my maven project, and it should use libraries-1 and library-2 with its dependencies. I cannot find maven archetypes for JavaFX 2 projects, and I will find any adequate information on how I can create a JavaFX application from Maven 3. I do not need any deployment on the Internet, it will only be a desktop application.

So, can anyone help in solving this problem?

UPD:

java.lang.NoClassDefFoundError: javafx/application/Application
...
Caused by: java.lang.ClassNotFoundException: javafx.application.Application

An exception occurs when I try to run an application that is built using pgras .

+7
source share
3 answers

So, I think you are already using Java 7, I know exactly what you need, for compilation you only need a dependency on javafx, so in your pom for the javafx application:

 <dependencies> <dependency> <groupId>com.oracle</groupId> <artifactId>javafx</artifactId> <version>2.0</version> <systemPath>${javafx.rt.jar}</systemPath> <scope>system</scope> </dependency> </dependencies> 

And in your maven settings.xml add (and adapt the path to your system):

 <profile> <id>javafx</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <javafx.rt.jar>C:\Program Files (x86)\Oracle\JavaFX 2.0 SDK\rt\lib\jfxrt.jar</javafx.rt.jar> <ant.javafx.jar>C:\Program Files (x86)\Oracle\JavaFX 2.0 SDK\tools\ant-javafx.jar</ant.javafx.jar> </properties> </profile> 

That should be enough to compile and make the jar file ... If you do not tell me, and I will post more information ...

+4
source

Thank you so much, this link is useful. So now my pom looks like this:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>info.kosmonaffft</groupId> <artifactId>javafx-maven-example</artifactId> <version>0.1</version> <packaging>jar</packaging> <name>javafx-maven-example</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeArtifactIds>junit,hamcrest-core</excludeArtifactIds> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>package</phase> <configuration> <target> <taskdef name="jfxjar" classname="com.sun.javafx.tools.ant.FXJar" classpathref="maven.plugin.classpath"/> <jfxjar destfile="${project.build.directory}/${project.build.finalName}"> <fileset dir="${project.build.directory}/classes"/> <application name="${project.name}" mainClass="info.kosmonaffft.jfxexample.App"/> <resources> </resources> </jfxjar> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>com.oracle.javafx</groupId> <artifactId>ant-javafx</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>C:\Program Files\Oracle\JavaFX 2.1 SDK\tools\ant-javafx.jar</systemPath> </dependency> </dependencies> </plugin> </plugins> </build> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>javafx</groupId> <artifactId>javafx-rt</artifactId> <version>2.1</version> <scope>system</scope> <systemPath>C:\Program Files\Oracle\JavaFX 2.1 SDK\rt\lib\jfxrt.jar</systemPath> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> </dependencies> </project> 

So, now you can run the application from the command line "java -jar myapp.jar", but I have not tested how it will work with dependencies.

+2
source

I am adding another answer because it is long and it shows how I am doing to generate a signed jar and a JNLP web start file.

So, first I create a certificate to be able to sign the bank (you will be asked to enter some information, I used "superpass" for passwords, see where it is used in pom):

 cd src/main/java mkdir jnlp cd jnlp keytool -genkey -alias signFiles -keystore keystore.jks 

And then I use this pom.xml (which has a parent pom, but it does not contain anything related to javafx):

 <?xml version="1.0" encoding="UTF-8"?> <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> <parent> <artifactId>testfx</artifactId> <groupId>ch.pgras</groupId> <version>1.0-SNAPSHOT</version> </parent> <groupId>ch.pgras</groupId> <artifactId>hellofx</artifactId> <version>1.0-SNAPSHOT</version> <name>hellofx</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>com.oracle</groupId> <artifactId>javafx</artifactId> <version>2.0</version> <systemPath>${javafx.rt.jar}</systemPath> <scope>system</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <configuration> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> <goals> <goal>copy-dependencies</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>package</phase> <configuration> <target> <taskdef name="jfxdeploy" classname="com.sun.javafx.tools.ant.DeployFXTask" classpathref="maven.plugin.classpath"/> <taskdef name="jfxsignjar" classname="com.sun.javafx.tools.ant.FXSignJarTask" classpathref="maven.plugin.classpath"/> <jfxdeploy width="800" height="600" outdir="${project.build.directory}/deploy" outfile="${project.build.finalName}"> <info title="${project.name}"/> <application name="${project.name}" mainclass="webmap.WebMap"/> <resources> <fileset dir="${project.build.directory}" includes="*.jar"/> <fileset dir="${project.build.directory}/dependency" includes="*.jar"/> </resources> <platform javafx="2.0"> <jvmarg value="-Xms64m"/> <jvmarg value="-Xmx256m"/> </platform> </jfxdeploy> <jfxsignjar destdir="${project.build.directory}/deploy" keystore="${project.basedir}/src/main/java/jnlp/keystore.jks" storepass="superpass" alias="signFiles" keypass="superpass"> <fileset dir="${project.build.directory}/deploy" includes="*.jar"/> </jfxsignjar> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>com.oracle.javafx</groupId> <artifactId>ant-javafx</artifactId> <version>2.0</version> <systemPath>${ant.javafx.jar}</systemPath> <scope>system</scope> </dependency> </dependencies> </plugin> </plugins> </build> 

Finally, I run mvn install and the result will be in target / deploy ...

good luck :)

0
source

All Articles