JNA UnsatisfiedLinkError, but jna.library.path is set - jna

I'm using the following code to load a dll in JNA (irrelevant code is left out):
public class JNAMain {
public interface PointShapeBuffer extends Library { ... }
public static void main(String[] args){
System.setProperty("jna.library.path", "c:\\jnadll");
System.setProperty("java.library.path", "c:\\jnadll");
PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
}
}
And I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'FileGDBAPI': The specified module could not be found.
I've also tried setting the VM args. Any suggestions would be great.
Edit: For reference, I am using a publicly available library found here (registration is required).

In my experience you usally see this error when calling 32bit native dlls from a 64bit jvm on 64bit Win7. Win7 works differently for 64bit and 32bit applications.
On 64bit Win7 you can call functions in native 32bit dll's, but you need to use a 32bit JVM.
Download and install 32bit Java Runtime Environment (JRE). You can install a 32bit and 64bit jvm on the same machine, just make sure they are installed in seperate directories.
Ensure you run the 32bit JRE instead of the default 64bit JVM when you execute your program. Either A) change your CLASSPATH and JAVA_HOME environment variables to point to the 32bit jvm, or write a script to set the CLASSPATH and JAVA_HOME and launch you application.
The reason for this is 32bit dll's are incompatible with 64bit applications, and 64bit Win7 uses a 32bit emulator to run 32bit applications. Although Windows Libraries might be called named xxxx32.dll (e.g. user32.dll) the libraries in the System32 folder on a 64bit Win7 are 64bit libraries, not 32bit, and the libraries in SysWOW64 are 32bit libraries, confusing right?!?
You can also place the library in the 32bit system folder (SysWOW64) and make the JNI call from within a 32bit JVM.
Check out the following link for a full explanantion as how 64bit Win7 handles libraries;
http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm
And if you really want to help yourself get to sleep, trying starting on this ;)
http://msdn.microsoft.com/en-us/windows/hardware/gg463051.aspx

Change your:
Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
to:
Native.loadLibrary("C:\\jnadll\\FileGDBAPI.dll", PointShapeBuffer.class);
If you dive into the jna source code enough you will find a nice little hook in the NativeLibrary class:
/** Use standard library search paths to find the library. */
private static String findLibraryPath(String libName, List searchPath) {
//
// If a full path to the library was specified, don't search for it
//
if (new File(libName).isAbsolute()) {
return libName;
}
...
So it will catch if you just passed an absolute path and not even use the searchPath. This was why you dont have to worry about jna.library.lib.

You need to specify the folder containing your DLL, not the DLL's actual path.
e.g. for baz.dll at c:\foo\bar\baz.dll, the path should be set to c:\\foo\\bar. (note in Java if you're using backspaces you'll have to escape them with backslashes)

You might want to download the latest version with jna.jar and platform.jar and just include those. No need to set the path then.

Like it was already mentioned in some comments: checks your Dependencies of your DLL/Library. Best Tool for this is Dependency Walker (http://www.dependencywalker.com/). Only if all your Dependencies are fulfilled, jna finds your DLL.... took me quite long to figure this out

it is may be because there is the conflation into the lebweb kit. I am not sure but that has to be that only now u can do one thing try this.
$ dpkg -l | grep -i jna
try this command and if u getting this output
ii libjna-java 3.2.7-4 Dynamic access of native libraries from Java without JNI
or any other output then this u need to remove then that jna from the system because if program itself have jna jar with that then there is no need of system jna for the same. so do something like this.
sudo apt-get autoremove libjna-java
and try for restart that application again. it will run and it is not running then try to install new version of libwebkit-gtk.
hope this will help. this helped me.

Related

javac not recognizing external libraries

I have a working version of my project in eclipse.
I exported the project as a runnable jar.
Extracted (after converting to .zip)and tried to compile a particular java file from the command prompt
(Doing it this way since I have a project requirement, where input parameter inside that particular file can be modified and recompiled/run by users who wont have Eclipse)
I have used some external libraries( for Eg:json-simple,gson etc).They arent getting recognized , during compilation.
But if I run the class file(from the Eclipse compiled version), it gets executed properly
a)Tried to compile from root folder(using package name)
javac packageName.javaFileName.java
b) and went inside the package and compiled directly.
javac javaFileName.java
The a)part didnt compile at all saying classNotFound. The b)part started compiling but threw an error where none of the external libraries got recognized.(Getting --> error: cannot find symbol for places wherever the code/import of the external lib is used)
a)Tried to compile from root folder(using package name) javac
packageName.javaFileName.java b) and went inside the package and
compiled directly. javac javaFileName.java
The a)part didnt compile at all saying classNotFound.
Yes. javac requires you to specify a filesystem path to the (first) source(s) to compile. You appear instead to have tacked .java onto the end of the desired fully-qualified class name. Probably you want to compile from the root of the unpacked jar, specifying a correct path:
javac [options] package/name/className.java
for class package.name.className. (You can also compile from a different working directory if you specify an appropriate option, as discussed below.)
The b)part
started compiling but threw an error where none of the external
libraries got recognized.(Getting --> error: cannot find symbol for
places wherever the code/import of the external lib is used)
If the class you're compiling depends on others that also need to be compiled then javac would likely make a similar complaint about them. Either compile from the root (as in (a)), or specify the path to the source root via the -sourcepath option. Either way, there's no reason to descend into the source tree to compile.
But the external libs are actually a separate, albeit related, question. You don't need to compile these, but you do need to tell javac to use them as sources of classes. You would do that via the -classpath option, which you can abbreviate to -cp. If those were packaged in the jar itself (i.e. a "fat jar") then that should be fairly easy, something along these lines:
javac -cp .:lib/dependency1.jar:lib/dependency2.jar package/name/className.java
The "lib" part may vary, and the separator definitely differs depending on OS (on Windows it is ;, whereas on Mac / Linux / Solaris is is :, as shown).
If the external libs were not packaged into the main jar then the procedure is the same, but you might have a bigger challenge finding the needed jars. Also, such a jar is probably not runnable if you move it to a different machine. Nevertheless, you should probably look in META_INF/MANIFEST.MF, as it should contain the needed information.

How to install Lua libraries on separate folder

Hello i would like to change folder that luasocket is installing to how can i do that ? My plan is at the end i want to export my lua file as exe and use it to run my server. I want to put luasocket inside Project file so other windows computer wont have problems (I am using Windows computer too). Thanks for helping.
my code
Main.lua
lpackage.path = package.path..';./libs/lua/?.lua'
package.cpath = package.cpath..';./libs/socket/?.dll;'
This is my Project tree
Project
-libs
--lua
Assuming you keep the name of the luasocket DLL the same (which is usually, core.dll), you need to use ./libs/?.dll instead of ./libs/socket/?.dll, as the question mark will be replaced with socket/core when socket.core module is required from socket.lua. You'll need to put core.dll in libs/socket folder.
You will also need to have lua.dll present (as the core.dll is usually compiled against it) or use a proxy dll if your executable statically compiles lua interpreter.

Windows Service Installation .NET-4.5 Cannot load the exe file

I am trying to install a windows service with installutil in cmd and this is the msg I get:
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///D:\inst
all\DemoWinProject.exe' or one of its dependencies. The module was expected to contain an
assembly manifest..
Can you help me out whats the prb ???
I have not seen that problem directly, but a very brief search found this link that may have the answer you seek. In a nutshell, make sure you're using the right version of InstallUtil.exe for the .NET framework targeted by your application and that you do not have any x86/x64 inconsistencies within your assemblies.
FWIW, I personally do not like using InstallUtil.exe to install my Windows service; I prefer the Windows service perform its own installation/uninstallation. This is a fairly straightforward thing to do, as I've shown here.
HTH.
I fixed this problem by writing the path where my InstallUtil.exe is and then Write the command InstallUtil and then write the path where my exe file that needs to be install is.
Note : Make another copy of debug folder in another place and install the exe file from that path. This is because anytime you make a built the exe file changes.So to prevent the changes of the installed .exe make a copy of it in another place and install it.
ex.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>installutil c:\Documents\Debug\WindowsService.exe

Dart Editor: It didnt work?

I launched Dart Editor yesterday but it didn't work giving the error:
("A Java Runtime(jre) or Java Development Kit(jdk) must be avaible in
order to run DartEditor. No Java virtual machine was found after
searching the following loacations:
C:\Users\name\Donwloads\darteditor-windows-x64\dart\jre\bin\javaw.exe
jawaw.exe in your current PATH ")
Do you think how i going to fix this error ?
Thanks
Checkout this link:
https://www.dartlang.org/tools/editor/troubleshoot.html
"Launching Dart Editor"
Your Java version should have the same bit width as your Dart Editor version. For example, if you're using a 64-bit Dart Editor, then you should use 64-bit Java. Otherwise, you might see a message like this when you try to launch Dart Editor:
Failed to load the JNI shared library "C:\Program Files(x86)\Java\jre6\\bin\client\jvm.dll
To determine which version of Java you are running, do one of the following:
1-Go to CMD type java -version.
2-Go to Start -> Programs and Features.
Specifying the Java runtime
If necessary, you can specify the Java runtime that Dart Editor uses. Go to your Dart installation directory and add the following two lines to DartEditor.ini immediately before the existing ‑vmargs line:
-vm
/full/path/to/java
Important: On Windows, use double backslashes (\) as the directory separator:
-vm
c:\\bin\\java_jdk1.7.0\\bin\\javaw.exe
For example, DartEditor.ini might have:
-vm
/usr/local/buildtools/java/jdk-64/bin/java
-vmargs
You just need to download the Java Development SDK and your Java version should have the same bit width as your Dart Editor version. For example, if you're using a 64-bit Dart Editor, then you should use 64-bit Java. Otherwise, you might see a message like this when you try to launch Dart Editor:
You can download it here:
http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=otnjp
and specify the java/bin directory in the darteditor.ini file.you can specify the Java SDK that Dart Editor uses. Go to your Dart installation directory and add the following two lines to DartEditor.ini immediately before the existing ‑vmargs line:
-vm
/full/path/to/java
Important: On Windows, use double backslashes () as the directory separator:
-vm
c:\\bin\\java_jdk1.7.0\\bin\\javaw.exe
For example, DartEditor.ini might have:
-vm
/usr/local/buildtools/java/jdk-64/bin/java
-vmargs
If it still doesn't work then you can follow this:
https://www.dartlang.org/tools/editor/troubleshoot.html
I made jre folder in my dart program folder.
And loaded there latest JRE. (Java runtime environment)
It stays in every new darteditor installation.
Better / right way would maybe be using path clause...
I dont know how to.. / dont want to use it.
My choise might need to load new version of jre now and then.
Hope this helps you...

Copying System32 DLL using MSYS breaks the 64bit being of the library

Under Windows 7 64bit, the *32.dll from System32 are 64bit libraries (according to Dependency Walker - depends.exe x64). A strange issue I noticed is that doing - for example - cp /c/System32/ws2_32.dll /c/mingw64/some/lib/libws2_32.dll in the MSYS Shell is breaking/converting the DLL to 32bit file (still according to Dependency Walker)... While copying/renaming it through Windows Explorer keep it unchanged... Still weird. If anyone has an explanation...
Or did I miss something about cp command usage...
Note: I already tried options like --preserve=all or --symbolic-link.
Thanks.
cp is somehow (either directly or due to the parent process that you're running it from) running as a 32-bit process. File System redirection is kicking in and you're actually copying ws2_32.dll from the C:\Windows\SysWOW64 directory instead - where it already exists as a 32-bit DLL.
32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access.

Resources