MySQL-Connector does not work after using JLink in a JavaFx project - javafx

I am trying to create an executable out of my JavaFX project that uses mysql-connector driver to connect to a local database. After i generate the JLink folder via the pom.xml file, when i run my application, the connection between the database and the app does not work (Running the application in the IDE makes everything work fine). I am using InteliJ as my IDE, MySQL for the database and i think the connector is a jar file without a module-info.jar file which is causing issues in JLink.
I did some digging and i found out that mysql-connector can not be added directly via Jlink. I've seen some workarounds (for example: moditect) but i still can't figure it out. Any help is greatly appreciated!

You can't use jlink to directly create an executable file if your application is not fully modular. However, you can use a combination of jdeps, jlink and jpackage to create an application bundle or an installer. You might want to have a look at this tutorial: https://github.com/dlemmermann/JPackageScriptFX

Related

How to run javafx with maven desktop application from a jar file outside Netbeans 11 on my laptop or another ones?

I am working on Netbeans apache 11.1. I developed so many desktop programs using java and could run them almost on any computer. But when I moved to JavaFX technology with maven I wanted to redevelop almost the same desktop apps using JavaFX, and everything worked fine into Netbeans 11.1. The problem is when I want to jar my apps and distribute them outside of Netbeans they actually do not work.
I tried everything I did in the past (which worked just fine) for instance: adding Class-Path and setting Main-Class to manifest but still does not work. I searched through a lot of forums and sites but still cannot run my app outside of Netbeans.
My code is as any code combination of JavaFX, Maven, CSS, and FXML. Everything works just fine into Netbeans. The problem is outside of it.
Although I've added openjfx-12.0.2_windows-x64_bin-sdk to windows environment path, when I attempted to run jar that's been generated by Netbeans using cmd I just get this ERROR: javafx runtime components are missing, and are required to run this application. ANY HELP PLEASE?
I don't know if I'm understanding your problem right (if not I'm sorry).
Runnable JAR JavaFX
What once helped me, was create a new run configuration (in intellij) with the main class and the JRE. After that I created a Run Maven Goal with the command line
assembly:single

Im building .jar of my program in InteliJ, but I added external .jar with JTatto LookAndFeel and the app doesn't work from desktop. How to repair it?

It's simple application. I'm pretty sure it doesn't work now from Desktop, because of external .jar added at the IDE.
Ok, basically just go in project settings, dependencies, add your jar (dont export) and then build normally
I had to create new project to make it work

How do I export a tornadofx application?

I finished writing a little tornadofx app in IntelliJ CE and now want to export it as a single file which can be downloaded and launched by users. For now it would be sufficient to provide a single jar file. But it would be also great to know on how to export a self contained installer for OSX, Windows and Linux. Unfortunately I don't know how to do any of that. Can you help?
Have a look at the FxLauncher project, which is also from the creator of tornadoFX. FXLauncher allows you to easily distribute your javafx/tornadoFX application. The project provides a maven-plugin which allows you to generate a self containing javafx/tornadoFX application that you then publish to a web-server or common directory (e.g an internal app in your company network). After that you can generate native installers for Linux, OSX and Windows. The installer itself will only install a small app, which will know the location of your web-serve or directory. On startup it will download the latest deployed version of you application and run it.
Additional links:
GitHub-project
Introduction screen cast
Customizing update ui
In case you want a single jar file, you can export it as a regular Java program (not the JavaFX option in IntelliJ). You do this by creating and building an artifact.
Go to the Project Structure window, and from there select Artifacts
Click the "+" icon to create a new artifact, and select JAR > From modules with dependencies...
Select the main class and press OK
And that's it, the artifact has been set up, now, to generate jar file, just go to Build > Build Artifacts menu, and select the newly-made artifact, and the IntelliJ will generate the jar file in the "out" directory.
Not sure if this is the best solution, but it's what I've been using, and it works for me.

Being able to run java application on different computers without JDK

How can I send my java application to a friend without having to send the entire project and being dependent on him having JDK? I'm aware of the .jar-file's existence, but I don't know how to proceed. I would like to be able to just send him the .jar-file or an executable file.
Any ideas?
Compile it to native code using a compiler such as http://en.wikipedia.org/wiki/GNU_Compiler_for_Java
Also, he doesn't need the JDK, just the JRE.
Did what #Barranka said regarding the dist folder, didn't know that worked until I read the readme file as #Barranka suggested.
So to quote what #Barranka said:
If you work with NetBeans, when you "build" your project, a dist
folder is generated, and your "packed" app is stored there. You can
send the contents of this folder. Read the "readme" file in that
folder. – Barranka
You can send the JAR file alone provided your program does not depend on other libraries. Assuming that there is a main() method and Main Class is configured in the JAR's manifest, the person can run it by Double Clicking (on windows) or use the command line
java -jar <jar_file_name>.jar
You cannot execute a Java application without a Java Virtual Machine, so you need one.
Your friend has to download a JRE/JDK, or you can provide it with your application directly as it (the JRE and your project in an archive) or provide it as a native compile code using GCJ or Excelsior Jet which will compile your application and a JRE.
As you can see the is no solution for your question, but there is one for your problem : ask your friend to download a JRE.

java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path

I'm trying to access a Berkeley DB database file (say Test.db) from the java code and then want to read all the pairs from it. I'm using the com.sleepycat.db.* and com.sleepycat.bdb.* packages ( NOTE: Not Oracle Berkeley DB JE )to do this task. For the implementation, I did exactly as described in this BerkeleyDB Java API Tutorial
So, when I run this project from eclipse I got this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path
and from the stack trace, source for this exception occured from this line
env = new DbEnv(0);
I tried to set it from the java command
$java -D<name>=<value>
but still it didn't work.
My goal is to export this project into a jar file and use it to read BDBs anywhere . Anyone who knows how to get out of this, I appreciate your help. It would be great if I can be redirected to any working tutorial for accessing Berkeley DBs from java code too. Thanks !!
SOLUTION: After a lot of work, I found out that the Sleepycat API that I'm working on is using native libraries that are written in C/C++ through the JNI. Berkeley DB that is installed on my PC didn't have the shared object file db_java-4.2 (to be accurate, file name is libdb_java-4.2) which means that this BDB is not configured for java APIs.
So, the solution is to start the installation of BDB from scratch again by enabling the java configuration.
I had the same problem.
Like kK_Pulla mentioned, the sleepycat API using native libraries written in C/C++ through the Java Native Interface. So making Sleepycat API calls means the java code is ultimately going to call compiled C/C++ code.
If you are getting the "java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path" error then it is likely that, at least it was in my case, you have not included the relevant native libraries in your project.
I would describe what I did to fix it in my case. Firstly let me describe my environment.
IntelliJ maven Java project on a linux machine.
Built Berkeley DB version 18.1.40.
The Berkeley build included the --enable-java switch in the configuration phase.
I included the db.jar (found in the build_unix directory) as a module dependency through the Intellij menus File> Project Structure. I selected Modules under Project settings on the left pane and then under the dependencies tab I added the db.jar file as a dependency.
This was the state of my project before I encountered the UnsatisfiedLinkError. To fix that I added the native libraries (found in the unix_build/.libs directory) to the project. You can do this by selecting the File menu> then Project Structure. On the left pane under project settings select Libraries and then click the + sign on the right pane to add the directory for the native libs.
This fixed my problem.

Resources