1

Context

I want to use JavaFx with clojure.

I am aware of http://nailthatbug.net/2011/06/clojure-javafx-2-0-simple-app/

Question:

Is there a way to make JavaFX work with Clojure using native-deps in lein instead?

Thanks!

user1383359
  • 2,673
  • 2
  • 25
  • 32

4 Answers4

3

I've created a simple Clojure and JavaFX example on Github. Testing on Ubuntu I had to install the JavaFX runtime into my local Maven repository, using the deploy:deploy-file target (install:install-file did not work for me).

mvn deploy:deploy-file -DgroupId=local.oracle -DartifactId=javafxrt -Dversion=2.2.0 -Dpackaging=jar -Dfile=/usr/lib/jvm/java-7-oracle-amd64/jre/lib/jfxrt.jar -Durl=file:/home/raju/.m2/repository

Make sure you have the following arguments set correctly:

  • -Dfile={full path to jfxrt.jar in jre/lib folder}
  • -Durl=file:{full path to Maven repository, e.g. $HOME/m2.repository}

In the project.clj, I added the dependency based on the -DgroupId and -DartifactId values when installing the JAR into the repository. If you use change these values, make sure to change the dependency accordingly:

[local.oracle/javafxrt "2.2.0"]

Java was able to load the binary libraries without any problems. If Java reports problems loading a binary library, e.g.

Caused by: java.lang.UnsatisfiedLinkError: Can't load library: /usr/lib/jvm/javafx-sdk/rt/lib/amd64/libglass.so

check out these two question on SO:

What is LD_LIBRARY_PATH and how to use it?
java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

Community
  • 1
  • 1
raju-bitter
  • 8,906
  • 4
  • 42
  • 53
1

Because JavaFx has native dependencies your option are limited to, ]

  • shipping these dependencies with your project (including them),
  • creating a package that you can depend on which has them (providing them),
  • or having your package require the user to install them in some other way.

Because the tutorial you link to covers the case where the user of your package/program installs JavaFx on their own, by using robert.hook and depending on the end-user's package manager to provide the actual native dependencies. I'll cover how to have your package/program include the dependencies.

native-deps can be used to ship native dependencies with your package. You just need to add all the .so, .dll, .etc files in the appropriate directories. I think the projects github page does a better job than I of explaining the structure.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • Sorry, my question is unclear. My focus is _using_ JavaFX, not (yet) shipping FX. If I'm not misreading your link, that is about packaging native dependencies? – user1383359 Jun 20 '12 at 01:14
1

The link in the question is broken so I can't see your example, but with Java 8, JavaFX is now part of the standard JDK/JRE. I therefore expect the native dependency issue to be irrelevant at this point.

Julien Chastang
  • 17,592
  • 12
  • 63
  • 89
0

Not sure if this will work for others, but this appears (so far) to have worked for me:

mvn install:install-file -DgroupId=javafx -DartifactId=javafx -Dversion=2.1.0 -Dpackaging=jar -Dfile=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre/lib/jfxrt.jar

I have no idea why this works, but I believe jfxrt.jar has the files I need. Then, after this, I kindle it in project.clj as

[javafx "2.1.0"]

in the :dependencies (not :native-deps) section.

[Having written this, I really have no idea why this even appears to work.]

user1383359
  • 2,673
  • 2
  • 25
  • 32
  • java is likely able to load the native lib dependencies directly from your computer by looking in (assuming linux) LD_LIBRARY_PATH. The jar file contains essentially a list of the dependencies it needs loaded and leaves it up to java to find them on the local filesystem. – Arthur Ulfeldt Jun 20 '12 at 02:39