Using export or an absolute path to run the produced jar file (HelloWorld.jar).

cp stands for the CLASSPATH

helloworld.Main is the main class with the package name

$ export PATH=$HOME/.netbeans/6.5/javafx-sdk/bin:$PATH

$ javafx -cp HelloWorld.jar helloworld.Main

Trying java -jar HelloWorld.jar

Running the jar file as mentioned before is fine. But it's somehow the source of many problems especially if you give the absolute path to your javafx-sdk !!!. And it's also unusual for Java Developers.

If you try to run the Jar using "java -jar HelloWorld.jar", you will get some error messages. The main messages is : ClassNotFoundException. The program exists with "Could not find the main class: helloworld.Main. Program will exit" message.

This is a well known Exception, when developing Java programs. Isn't it ?

This normally means in Java that the class that contains main method was not found, or the "Main-Class" section in MANIFEST.MF, in the jar file is missing or has errors.

The problem here is different, let take a look at "MANIFEST.MF" and jar's contents.

As you can see, "Main-Class" is in "META-INF/MANIFEST.MF", and has the correct class name with it's package. A new line is inserted to satisfy specification at the end of the file.

The Main.class also is in the jar in the correct location

What is the problem here ?

The answer is simple : Java can not locate JavaFX run-time in the CLASSPATH. It needs indication about this location.

Is there a simple workaround ?

Yes. Normally if you specify the path to JavaFX run-time in the classpath, you'll get no more errors. A better way is to let NetBeans do the work. Please follow...

Copy javafx-sdk folder to a place of your choice.

$ cp -a $HOME/.netbeans/6.5/javafx-sdk $HOME/javafx-sdk

Note :You can use the copied folder if you want to play with JavaFX using the command line, compiler and interpreter. Or if you want to use "javafx -cp fileName.jar packageName.MainClass" as above.

Right click on the project name in NetBeans -> Select Properties

Select "Libraries" -> Click on "Add JAR/Folder"

Inside the javafx-sdk/lib folder (copied above)

There are two folder "desktop" and "share"

Select all jar files inside "desktop" -> OK

Repeat Add JAR/Folder, and select all jars in "share" -> OK

Uncheck "Build Projects on Classpath"

Click on OK when all jars are added

Right click on your project -> Clean and Build Project

That's All :)

You will find in the "dist" folder HelloWorld.jar file and "lib" folder packaged for you by NetBeans. This contains the needed JavaFX run-time.