3

I download JavaFx from here. I placed it in my home directory(anto) under the name javafx. Then I did something like this :

vi ~/.bashrc

and added the following lines:

javaFx_home=/anto/javafx/rt/lib/jfxrt.jar
export PATH=$PATH:$javaFx_home

But after providing the classpath, I tried running :

groovy MyProgram

(which depends on the JavaFx classpath).

But that throws me an error. Where I went wrong?

0

4 Answers 4

2

Automatically: (via webupd8 helper ppa repository)

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Note: You can replace oracle-java7-installer with oracle-java8-installer or oracle-java9-installer. You will need to accept the Oracle End User License Agreement prior to installation (this isn't required with OpenJDK, so if a OpenJDK back-port is released for 12.04, please update this post! :)

Manually:

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Jul 5, 2012 at 12:59
1

You can try setting the CLASSPATH instead of PATH. Java tries to load it's classes from the locations referenced by CLASSPATH.

  • First check your existing classpath with echo $CLASSPATH. Like PATH, the entries for CLASSPATH are separated with :(colon). The presence of a . entry under CLASSPATH means java can always load classes from current directory.
  • To add a .jar library to your CLASSPATH you should open the file ~/.profile and add export CLASSPATH=$CLASSPATH:path to .jar to it. Like in your case it should be

    javaFx_home=/home/anto/javafx/rt/lib/jfxrt.jar
    export CLASSPATH=$CLASSPATH:$javaFx_home

    if . was not present in your previous CLASSPATH entry then modify the last line as
    export CLASSPATH=$CLASSPATH:$javaFx_home:.
0

Here is what I've found so far.

I downloaded JavaFX SDK 1.2 and 2.2. They have removed some files from JavaFX SDK.

For 1.2

virpara@Ascension:~$ tree -L 2 '/home/virpara/Desktop/javafx-sdk1.2' 
/home/virpara/Desktop/javafx-sdk1.2
|-- bin
|   |-- javafx
|   |-- javafxc
|   |-- javafxdoc
|   `-- javafxpackager
|-- COPYRIGHT.html
|-- docs
|   |-- api
|   |-- emulator.html
|   |-- index.html
|   |-- javafxc.html
|   |-- javafxdoc.html
|   |-- javafx.html
|   |-- javafxpackager.html
|   `-- manpage.css
|-- emulator
|   `-- bin
|-- invoice.properties
|-- lib
|   |-- desktop
|   |-- javafx-runtime.properties
|   |-- mobile
|   `-- shared
|-- LICENSE.txt
|-- profiles
|   |-- desktop.properties
|   `-- mobile.properties
|-- README.html
|-- samples
|   |-- DisplayShelf
|   |-- DisplayShelfMobile
|   |-- DragAndDrop
|   |-- index.html
|   |-- InterestingPhotos
|   |-- LocalSearch
|   |-- MediaBox
|   |-- PathAnimation
|   |-- PhotoEffects
|   |-- PhotoFlip
|   |-- shared
|   `-- SpringAnimation
|-- servicetag
|   `-- registration.jar
|-- src.zip
|-- THIRDPARTYLICENSEREADME.txt
`-- timestamp

23 directories, 23 files

For 2.2

virpara@Ascension:~$ tree -L 2 '/home/virpara/Desktop/javafx-sdk2.2.0-beta' 
/home/virpara/Desktop/javafx-sdk2.2.0-beta
|-- bin
|   `-- javafxpackager
|-- COPYRIGHT.html
|-- docs
|   `-- api
|-- lib
|   |-- ant-javafx.jar
|   |-- javafx-doclet.jar
|   `-- javafx-mx.jar
|-- README.html
|-- rt
|   |-- COPYRIGHT.html
|   |-- lib
|   |-- README.html
|   `-- THIRDPARTYLICENSEREADME.txt
`-- THIRDPARTYLICENSEREADME.txt

6 directories, 10 files

There is only javafxpackager script in javafx-sdk2.2.0-beta/bin (javafx, javafxc, javafxdoc scripts are removed) it means that if you export javafx-sdk2.2.0-beta/bin to your PATH variable and try to execute javafx --version in terminal it can't find javafx because there is no executable named javafx.

Well I've no experience with JavaFX but probably they have removed other three scripts because it would not be needed and perhaps javafxpackager would do the thing or java is enough for that.

You've tried to include whole path to jfxrt.jar to PATH variable.

it won't work because it can't automatically pass to -cp parameter. So, you must give full path to jfxrt.jar as -cp /anto/javafx/rt/lib/jfxrt.jar

java -cp /anto/javafx/rt/lib/jfxrt.jar MyProgram.java

I know it is not a solution.

0

I have the same problem, and @samik answer works for me !

Into my ~.bashrc , like @samik say :

export JAVAFX_HOME=/usr/lib/jvm/javafx-sdk2.2.0-beta/rt/lib/jfxrt.jar
export CLASSPATH=$CLASSPATH:$JAVAFX_HOME:.

Now a little source .profile and we try with an example

touch JavaFxText.java

I cut/copy this example code into the file :

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 * Simple demonstration of JavaFX text support.
 * 
 * @author Dustin
 */
public class JavaFxText extends Application
{
   /**
    * Start demonstration of JavaFX text capabilities.
    * 
    * @param stage Stage for JavaFX application.
    * @throws Exception Exception in JavaFX application.
    */
   @Override
   public void start(final Stage stage) throws Exception
   {
      stage.setTitle("Simplistic Example of JavaFX 2.0 Text Capabilities");
      final Group rootGroup = new Group();
      final Scene scene =
         new Scene(rootGroup, 800, 400, Color.BEIGE);

      final Text text1 = new Text(25, 25, "(2007) JavaFX based on F3");
      text1.setFill(Color.CHOCOLATE);
      text1.setFont(Font.font(java.awt.Font.SERIF, 25));
      rootGroup.getChildren().add(text1);

      final Text text2 = new Text(25, 50, "(2010) JavaFX Script Deprecated");
      text2.setFill(Color.DARKBLUE);
      text2.setFont(Font.font(java.awt.Font.SANS_SERIF, 30));
      rootGroup.getChildren().add(text2);

      final Text text3 = new Text(25, 75, "(2011) JavaFX to be Open Sourced!");
      text3.setFill(Color.TEAL);
      text3.setFont(Font.font(java.awt.Font.MONOSPACED, 35));
      rootGroup.getChildren().add(text3);

      final Text text4 = new Text(25, 125, "(2011) JavaFX to be Standardized");
      text4.setFill(Color.CRIMSON);
      text4.setFont(Font.font(java.awt.Font.DIALOG, 40));
      final Effect glow = new Glow(1.0);
      text4.setEffect(glow);
      rootGroup.getChildren().add(text4);

      final Text text5 = new Text(25, 175, "(Now) Time for JavaFX 2.0!");
      text5.setFill(Color.DARKVIOLET);
      text5.setFont(Font.font(java.awt.Font.SERIF, FontWeight.EXTRA_BOLD, 45));
      final Light.Distant light = new Light.Distant();
      light.setAzimuth(-135.0);
      final Lighting lighting = new Lighting();
      lighting.setLight(light);
      lighting.setSurfaceScale(9.0);
      text5.setEffect(lighting);
      rootGroup.getChildren().add(text5);

      final Text text6 = new Text(25, 225, "JavaFX News at JavaOne!");
      text6.setFill(Color.DARKGREEN);
      text6.setBlendMode(BlendMode.COLOR_BURN);
      text6.setFont(Font.font(java.awt.Font.DIALOG_INPUT, FontWeight.THIN, 45));
      final Reflection reflection = new Reflection();
      reflection.setFraction(1.0);
      text6.setEffect(reflection);
      rootGroup.getChildren().add(text6);

      stage.setScene(scene);
      stage.show();
   }

   /**
    * Main JavaFX application launching method.
    * 
    * @param arguments Command-line arguments: none expected.
    */
   public static void main(final String[] arguments)
   {
      Application.launch(arguments);
   }
}

And it's running

javac JavaFxText.java
java JavaFxText

Give the bounty to @samik, he deserves !!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .