Skip to content

Spring Tool Suite: Failed to load the JNI shared library

Last Updated on 17/08/2022

This tutorial will show you how to solve the Spring Tool Suite “Failed to load the JNI shared library” initialisation error.

spring tool suite failed to load the jni shared library error

The “Failed to load the JNI shared library” error is generally caused by two reasons:

  1. The architecture version (32 or 64 bits) of your Java and your Spring Tool Suite don’t match;
  2. Your STS.ini is pointing to your Java home directory instead of the Java executable.

Let’s explore the solutions for both cases.

Architecture version (32 or 64 bits) don’t match

JDK and STS come in two architectures, 32 and 64 bits, so the rule of thumb is to always run matching versions, either both of them being 32 bits (on 32 and 64 bits machines) or 64 bits (exclusive to 64 bits machines). Therefore, if the versions don’t match it is quite possible that your environment will not work as expected.

In order to check your Java version, run the following command which is going to print its version (64 bits in my case) at the last highlighted line:

C:\Users\bgasparotto>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

In regard to Spring Tool Suite’s version, just check which version you have downloaded from the website, but if you’re not sure, it usually follows a name pattern where the 64 bits version includes x86_64 as part of the file name, whilst the 32 bits doesn’t. In the image below, the first file is 32 bits and the second is 64:

Spring Tool Suite architecture versions

STS.ini not pointing to your Java executable

Spring Tool Suite is a Eclipse based tool, so it has a STS.ini file to setup its initialisation like Eclipse has its eclipse.ini file. That said file resides in the same directory of the STS.exe file and its default version looks like the following:

-startup
plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.550.v20170928-1359
-product
org.springsource.sts.ide
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.8
--add-modules=ALL-SYSTEM
-Xms40m
-Dosgi.module.lock.timeout=10
-Xverify:none
-Dorg.eclipse.swt.browser.IEVersion=10001
-Xmx1200m

As a result, it’s possible that the JRE path has been wrongly set in that file, specifying just the Java home folder instead of the Java executable javaw.exe itself:

...
-vm
C:\Users\bgasparotto\Documents\Java\jdk1.8.0_121\bin
-vmargs
...

In order to fix that, add the missing part as explained before:

...
-vm
C:\Users\bgasparotto\Documents\Java\jdk1.8.0_121\bin\javaw.exe
-vmargs
...

Now, you should be good to go.
Please let me know if by any reason none of these solutions have worked for you, so I can help you fixing it =]

References

17 thoughts on “Spring Tool Suite: Failed to load the JNI shared library”

  1. Hi
    Checked both version as well as the java executable in ini..both are correct..still getting the error:
    java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
    no swt-pi4-gtk-4934r6 in java.library.path
    no swt-pi4-gtk in java.library.path
    Can’t load library: /home/zeahmed/.swt/lib/linux/x86_64/libswt-pi4-gtk-4934r6.so
    Can’t load library: /home/zeahmed/.swt/lib/linux/x86_64/libswt-pi4-gtk.so

  2. after adding the vm field

    Error : Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit

  3. hi

    i don’t have anything like the field below in my sts executable file. Any assistance is appreciated

    -vm
    C:\Users\bgasparotto\Documents\Java\jdk1.8.0_121\bin
    -vmargs

Leave a Reply

Your email address will not be published. Required fields are marked *