Packaging a Swing application with JavaFX components into an executable JAR - java

I am having trouble packaging an application with both Swing and JavaFX components into a JAR file. Running it from Eclipse is fine. But when executing the Jar, errors occur: The main method is run, which calls the constructor of my app. The constructor calls a initAndShowGUI() method, which tries to create a JFXPanel for later addition to a JFrame, but fails with following error message: Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\User\bin\glass.dll. This library seems to be needed by JavaFX but is somehow not loaded. "Pure" JavaFX apps (without Swing) call something like a "preinitialitation" method for JFX that loads all the needed libs, I think (I'm not completely sure). Also, I've found information on how to deploy Java Web Start apps or applets (http://docs.oracle.com/javafx/2/deployment/deploy_swing_apps.htm), but nothing on "standard" JARs.
Has anybody done this before? I've been looking for a solution a lot but have not been able to find one. Help is highly appreciated!

Likely your issue is packaging related.
How did you package the app?
For example:
Did you use e(fx)clipse?
Did you use the the javafx ant tasks?
Did you use the javafxpackager?
I know (at least) the last two will work to build a Swing application with JavaFX components into an executable jar.
The SwingInterop sample includes an ant script for packaging the sample into an executable jar. The sample is downloadable from the javafx download site.
I highly recommend reviewing Why should I use the JavaFX ant tasks for packaging my Swing application? which post also includes the source for the SwingInterop sample build file.

Related

IntelliJ IDEA creating an MSI-installer for a JavaFX application

I'm trying to create an MSI-installer for my JavaFX application. This is briefly what I've done so far. I created a new artifact for JavaFX and selected the Native Bundle to be MSI in the Java FX -tab. After that, I built the artifact. When I opened the output -folder, there was no .msi installer. Instead, there were 3 other files (one HTML-, jar-, and jnlp-file). What am I missing here? Where is the MSI-file?
What you are looking for is all part of standard JDK 14. Its called jpackage.
If you need a tutorial to see how it works have a look here: https://github.com/dlemmermann/JPackageScriptFX

how to make my application (.jar) works on end-user's desktop

I'm using NetBeans 8.0 and my problem is when I make (clean and build) to my java project....the jar will be build in the current path of the project and works good with no problems, But, when I make a copy of the jar to my desktop, the application jar doesn't run. why?
Except for the most trivial programs you cannot just copy a jar file containing your classes to a target machine and expect it to run, as Sun never got around to do a well-defined single-file deployment method for a desktop application (similar to what WAR files do for web applications).
You must essentially copy your code, and the library jars you depend on, and a launcher script telling the JVM which jars you have, and an icon if you want that and usually more too. The lack of a standard method means that there are many ways to do it and you need to choose the one best suitable for you.
A solution for your problem here and now is to look at https://netbeans.org/kb/articles/javase-deploy.html which discusses how to deploy Java SE applications using netbeans by creating a runnable jar with an embedded classpath. I am not very familiar with Netbeans but the steps look very sensible and will teach you the details on the process.
When you get more experienced you will want to be able to automate the process more. The first step in that direction is to learn Maven - a bit tedious in the start but it pays of in the long run.

How to run Scuba project from Eclipse

I try to use Scuba project.I downloaded source with SVN checkout and imported it into Eclipse .Also i imported scuba_smartcards project. Everything is perfect but i have one problem.When i try to run scuba project like java application,have this error message:
Selection does not contains main type
I don't know is a correct to run this source like java application or not.By the way i created my own java class and i want to use scuba's source in main method
Ho i can solve my problem?
thanks everyone
P.s i also found source in github
https://github.com/credentials/scuba
I'm using scuba_sc_j2se
SCUBA is a framework, basically it is a library with active components. Libraries are not standalone applications so they will not contain a main method of their own. You cannot just run it, you need to write or copy an application that uses the framework through the API presented by SCUBA.
One of these applications is the jMRTD application from which SCUBA originated.

Utilizing jna library in application rather than applet

I'm trying to use a JNA library in my project.
My situation is as follows:
I have an applet that shows camera input.
If I run the Applet using the command run as applet I get the correct result:
an applet that shows the camera input
If I remove jna.jar from the build path it gives me error as expected.
If I rename the directory of the native plugins it gives me error as expected.
If I try to run the whole application I get the error:
GStreamer-WARNING **: Failed to load plugin C:/Users/aaa/Desktop/bbb/ccc/video/library/\windows64\plugins\libgstwavparse.dll on 30+ dlls
The path C:/Users/aaa/Desktop/bbb/ccc/video/library/\windows64\plugins\ is the one that if renamed makes the applet crash (so the correct one) and jna.jar and the library that used by JNA are imported in each project involved: the root project from which the application is started and the view project that instantiates the camera showing applet.
As previously suggested, I have tried
System.setProperty("jna.library.path","C:/Users/aaa/Desktop/bbb/ccc/video/library/windows64/plugins/" );
etc... in all possible forms to reference the correct directory but to no avail.
The library is a 3rd party library and actually should work.
The problems may be in my total lack of knowledge of JNA and/or Gstreamer or even of some basics at this point.
Is there any workaround? Why do the applet and application that instantiates the applet work differently when referencing DLLs... or Gstreamer DLLs... or the Processing 2.2.1 included Gstreamer DLLs?
Ok i managed to make it work this way: if i write a main directly in the View project and add the applet to a panel it now works... so that solves some issues(the applet was in a panel even before anyways)... the same exact dummy main gives the warning as before if run under root project alas: failed to load plugin:"correct path"
As said before i have a root project and a view project(N Vproject to be frank) the video lib is included in the VProject and the dlls are under is project resources. Is it possible that running the app from the main project something (like different system variables) end up causing problems?
Just not knowing the issue i precedently added and removed(and combinations) all that could be added in relation to jna platform and to tha jna-using-video lib to both projects.
i really do care about uncoupling in this case because im sort of writing a framework and this is a major limitation. Any insight?

Clarification for exporting a LibGDX game as an applet

I'm trying to follow the guide to export my project as a Java applet.
My project, as seen in Eclipse, has three directories:
Game
Game-Android
Game-Desktop
They were created using the UI Setup tool. The guide at http://www.thesecretpie.com/2011/05/being-like-minecraft-or-how-to-run-your.html is confusing and I don't understand these points:
Next step: add a new file called HelloWorldApplet.java (in the same
directory as other source files).
"The same directory as other source files". Well, I have three directories and they all have a source folder. In which of these three am I supposed to put this file? I tried placing it in Game, but Eclipse is unable to resolve com.badlogic.gdx.backends.lwjgl.LwjglApplet. If I put it in Game-Desktop it seems to be OK, but I'm not sure.
Create a directory called applet in your project dir.
Again, in which of my three directories?
Just export the whole project as jar in Eclipse
I can export a JAR for Game, Game-Android, or Game-Desktop. Which of these?
Related:
I happen to be using the JRuby JAR in my game to run some ruby scripting logic. Do I have to do something specific about it?
That blog is little old. For example, the JOGL backend is gone from recent version of Libgdx (so you don't need to worry about switching to the LWJGL backend). Also, the current LWJGL bundled into Libgdx is 2.9.0 (hopefully that doesn't change too much, though).
I believe the instructions are effectively packing up the "desktop" build of your app into an Applet (as the desktop is the only build that use the LWJGL backend), so assume Game-Desktop is the "same directory" that its talking about.
Thus, you should export the .JAR from your Desktop project.
On a related note, there is another way to run your game on the web, using the GWT backend. Check out the Setup & Running page (where its called "HTML5"). There are a bunch of caveats on using the GWT backend (not all Libgdx APIs work over there). (Hmm... I doubt this will work with the JRuby JAR, so probably not worth spending too much time on that.)

Categories

Resources