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

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.

Related

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

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

Runnable Jar from a JavaFX 8 project, JavaFX compenents are missing

i created a Javafx project using JDK 8 and when i tried to export it to a runnable .jar file, i got surprised that it doesn't run using CMD, and gives the following error :
"Javafx compenents are missing"
while it works perfectly during the compiling time(using the IDE) when i accessed the .jar files, i found it has just .class files (that i made), and the needed library files that haven't been exported (i made sure to select the "extract need library files extract required libraries into generated jar" option in Eclipse), is there a reason behind of this? and a way to solve it? thanks in advance
Ps: i tried this using Eclipse and Intellij IDE
I just wanna mention once again that I'm using JDK 8 where it has JavaFX library inside of it.
Did you try this?
There are detailed instructions on how to configure your IDE to run JavaFX with newer OpenJDKs (which do not come with JFX components in it).
It also explains how to create a new JavaFX Maven project from archetype, with all the necessary plugins to easily build your application while including the minimal Java components for it (using jlink).
This will ensure that anybody using your application will have those components.

Adding new paths for native libraries at runtime in Java9

I have an app that includes some native code. In an effort to make things easy for users to install and run, I have been extending the private field ClassLoader.sys_paths at runtime as described in this previous question: Adding new paths for native libraries at runtime in Java. With this hack the app can run with a simple unadorned java -jar app.jar command and the native objects will be located correctly in the installation directory.
This technique no longer works in Java 9 (see How to solve InaccessibleObjectException ("Unable to make {member} accessible: module {A} does not 'opens {package}' to {B}") on Java 9?). This article describes the changes to Java 9 and suggests a solution (adding arguments to the command line to open the module), but this defeats my original intent of allowing a simple execution of the java command.
Is there any way to change the native library search path at runtime, or is this considered too much of a loaded gun to leave lying around?

Getting Started with SQLite PCL

All,
I am struggling to get off the ground with SQLite. I cannot seem to find the right search terms to get the answer I need, so have come here.
I simply want to do this: have a single dll (PCL) that contains all my SQLite logic. I have installed the NuGet package SQLitePCL from Microsoft Open Technologies into this PCL project. I have written a single method that opens a connection.
I then have a test harness console application that references my PCL DLL project. That, in its root, has the file SQLite3.dll, that I downloaded from the SQLite site. Obviously, this console application calls my OpenConnection method in the library dll.
I am getting the error:
Additional information: A SQLite Wrapper assembly for the current platform was not found. Ensure that the current project references both SQLitePCL and the following platform-specific assembly: SQLitePCL.Ext
So my questions are:
where do I get that platform specific assembly from?
Is there an article on the web that specifically demonstrates how to do this?
Help gratefully appreciated,
Gray
Ok ... the answer to this was painfully simple. The platform specific assemblies are in the "packages\SQLitePCL.3.8.5.1\build" folder (put there by NuGet, of course). I just copied the dll from the sub folder Netcore451 into the root of my console app.

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.

Resources