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.
The “Failed to load the JNI shared library” error is generally caused by two reasons:
- The architecture version (32 or 64 bits) of your Java and your Spring Tool Suite don’t match;
- 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:
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
- bgasparotto – Change Eclipse JRE Path
- Stack Overflow – Failed to load JNI shared library
The second solution worked for me, thanks!
It worked on first try. Thanks for the article.
Thank you. It worked for me.
Grt !!! worked for me
Muito obrigado! Para mim resolveu, gratidão pela ajuda.
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
Thanks. It worked for me.
Fantastic !! It worked. Thanks
Wow. It worked for me too. Thank you so much.
after adding the vm field
Error : Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit
Thanks for the solution, it worked!
Its Lovely resolution……appreciated!
Thank you very much
it is not working for me help me to solve it
Are you getting the same error?
Could you please share the location of your Java installation and the contents of your
STS.ini
file?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
…
Hi, the file you need to change is not the executable one, but the `STS.ini` file =]
Great !! It worked.