"Could not find or load main class" Java runtime error

Hello!

I am trying to use JNA, but can obviously not see a simple problem. The code is a simple example I got from here. Unfortunately, I got my wires crossed and cannot see where the problem is. I searched the Web and found several sites where a solution is tried to be found for the problem, but no avail. :-(

To reduce the problem to its essentials, I use the command prompt in Windows 8.1 and do the following:
D:\Projekte\C>type *

ctest.c


/* ctest.c */

#include <stdio.h>

void helloFromC() {
    printf("Hello from C!\n");
}
D:\Projekte\C>gcc -o libctest.so -shared ctest.c

D:\Projekte\C>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\Projekte\C

2014-10-22  15:05    <DIR>          .
2014-10-22  15:05    <DIR>          ..
2014-10-21  16:02                93 ctest.c
2014-10-22  15:05            21.804 libctest.so
               2 Datei(en),         21.897 Bytes
               2 Verzeichnis(se), 490.275.999.744 Bytes frei

D:\Projekte\C>copy lib*.* ..\Java
libctest.so
..\Java\libctest.so überschreiben? (Ja/Nein/Alle): j
        1 Datei(en) kopiert.

D:\Projekte\C>cd ..\Java

D:\Projekte\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\Projekte\Java

2014-10-22  15:05    <DIR>          .
2014-10-22  15:05    <DIR>          ..
2014-10-22  13:20               354 HelloWorld.java
2014-10-21  16:50           946.973 jna-3.2.5.jar
2014-10-22  15:05            21.804 libctest.so
               3 Datei(en),        969.131 Bytes
               2 Verzeichnis(se), 490.275.999.744 Bytes frei

D:\Projekte\Java>type HelloWorld.java
/* Hello World! */

import com.sun.jna.Library;
import com.sun.jna.Native;

public class HelloWorld {
    public interface CTest extends Library {
        public void helloFromC();
    }
    static public void main(String argv[]) {
        CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
        ctest.helloFromC();
    }
}

D:\Projekte\Java>javac -classpath jna-3.2.5.jar HelloWorld.java

D:\Projekte\Java>java -classpath jna-3.2.5.jar:. HelloWorld
Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden

D:\Projekte\Java>

Open in new window


The runtime error reads in English Error: Could not find or load main class, in German Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden.

Where do you think I is the problem? As you can see, the code compiles properly.

Thank you in advance!
Hello-JNA-World.png
JNA-Hello-World.PNG
LVL 1
Ahmet Ekrem SABANSenior IT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krakatoaCommented:
Probably your classpath isn't set correctly.
0
CEHJCommented:
D:\Projekte\Java>java -classpath jna-3.2.5.jar:. HelloWorld

Open in new window

Wrong path separator - in Windows it's ';'
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Thank you for your replies! I can compile other Java files without problems. The Java file of interest uses JNA. This must be the cause of the problem, but the library I use contains the native elements.

I changed the separator from a colon to a semicolon and got another error message:
D:\Projekte\Java>java -classpath jna-3.2.5.jar;. HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'ctest': Das angegebene Modul wurde nicht gefunden.

        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at HelloWorld.main(HelloWorld.java:11)

D:\Projekte\Java>

Open in new window


However, libctest.o does include ctest.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

krakatoaCommented:
ctest is meant to be a String, isn't it? You seem to be using a CTest there.
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Personally, I just copied the example found in the Web... I do not mean something special; this seems to be the correct way to write it down I suppose.
0
CEHJCommented:
I think you might have your naming wrong. Try following this closely:

http://m-hewedy.blogspot.co.uk/2011/08/java-native-access-jna-by-example.html
0
CEHJCommented:
Before that, you can try

D:\Projekte\Java>java -Djna.library.path=. -classpath jna-3.2.5.jar;. HelloWorld

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
The line of code you send to execute before gives the same error message.

I tried the other example and got the following:
D:\Projekte\Java>type Test.java
import com.sun.jna.Library;
import com.sun.jna.Native;

public class Test {
        public interface Add extends Library
        {
                Add INSTANCE = (Add) Native.loadLibrary("add", Add.class);
                int add(int x, int y);
        }
        public static void main(String[] args) {
                Add lib = Add.INSTANCE;
                System.out.println(lib.add(10, 20));
        }
}

D:\Projekte\Java>javac -classpath jna-3.2.5.jar Test.java

D:\Projekte\Java>java -classpath jna-3.2.5.jar;. Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'add': Das angegebene Modul wurde nicht gefunden.

        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at Test$Add.<clinit>(Test.java:7)
        at Test.main(Test.java:11)
D:\Projekte\Java>

Open in new window

0
krakatoaCommented:
Have you checked the directory into which the header file went?
0
CEHJCommented:
You compiled with g++ exactly as per the example?
0
CEHJCommented:
btw i noticed you were compiled a shared object (.so). If you're using Windows, you should be compiling a DLL
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Hi, krakatoa! I can't see any header files of my own:

D:\projects>dir C Java
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\C

2014-10-22  16:55    <DIR>          .
2014-10-22  16:55    <DIR>          ..
2014-10-22  16:55                49 add.c
2014-10-22  16:55            21.582 add.dll
2014-10-21  16:02                93 ctest.c
2014-10-22  16:41               766 ctest.o
2014-10-22  16:42            21.804 libctest.dll
               5 Datei(en),         44.294 Bytes

 Verzeichnis von D:\projects\Java

2014-10-22  16:59    <DIR>          .
2014-10-22  16:59    <DIR>          ..
2014-10-22  16:55            21.582 add.dll
2014-10-22  16:44               216 HelloWorld$CTest.class
2014-10-22  16:44               495 HelloWorld.class
2014-10-22  13:20               354 HelloWorld.java
2014-10-21  16:50           946.973 jna-3.2.5.jar
2014-10-22  16:42            21.804 libctest.dll
2014-10-22  16:59               434 Test$Add.class
2014-10-22  16:59               508 Test.class
2014-10-22  17:01               332 Test.java
               9 Datei(en),        992.698 Bytes
               2 Verzeichnis(se), 490.275.942.400 Bytes frei

D:\projects>

Open in new window


And hi CEHJ! I use gcc of MinGW. Although I use now a DLL, I unfortunately still have the same problem.
0
CEHJCommented:
I tried the other example and got the following:

Try instead
D:\Projekte\Java>java -Djna.library.path=. -classpath jna-3.2.5.jar;. Test

Open in new window


Otherwise, you might have a bitness problem. Make sure you're compiling and running a 64-bit dll if you have a 64 bit machine
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Oh!!! :-o How can I find out whether the generated DLL is 32- or 64-bit?? You mean that a 64-bit system cannot read a 32-bit library, do you? Actually, I see a mingw32-cc.exe file and others starting with mingw32 in the MinGW bin directory. But there are also other similarly-named files, where this "prefix" is missing. Currently, I do not use them with the "prefix".
0
CEHJCommented:
Try

objbump -p add.dll

Open in new window


and post the result
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Here you go…
objdump.txt
0
CEHJCommented:
OK that at least shows that you have 32 bit dlls. This could give a bit more info:

D:\Projekte\Java>java -Djna.library.path=. -Djna.debug_load.jna=true -Djna.debug_load=true -classpath jna-3.2.5.jar;. Test

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Yes, this is the result:

D:\projects\Java>java -Djna.library.path=. -Djna.debug_load.jna=true -Djna.debug_load=true -classpath jna-3.2.5.jar;. Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'add': Das angegebene Modul wurde nicht gefunden.

        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at Test$Add.<clinit>(Test.java:7)
        at Test.main(Test.java:11)

D:\projects\Java>

Open in new window

0
CEHJCommented:
None of those debug parameters worked - that's odd
0
krakatoaCommented:
You said earlier that you couldn't find the header file - or any of 'your' header files at least. Shouldn't you be concerned about that?
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Well, I have written only a very short C files that do not have any header files of their own. Actually, I do not have any header files of my own & therefore not concerned about that. :-s
0
Duncan RoeSoftware DeveloperCommented:
Since you have it installed, I would try to  get your example running under Cygwin first.
0
Duncan RoeSoftware DeveloperCommented:
Think I see it. libctest.dll should be called ctest.dll (the lib prefix is a Linux thing)
0
Duncan RoeSoftware DeveloperCommented:
Also it needs to be in a folder in your PATH (CLASSPATH will not do).
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Well, I do not think that Cygwin is installed here. At least, I searched the C drive and couldn't find it. Also, the only 'Cygwin' word in this question is in your comment.

"It" lies in the folder of compilation, if you mean the newly relabeled file ctest.dll. So, it is actually on the first item '.' in the path. To make it clear what I've done, here is the code:

D:\projects\C>gcc -o ctest.dll -shared ctest.c

D:\projects\C>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\C

2014-11-12  09:18    <DIR>          .
2014-11-12  09:18    <DIR>          ..
2014-10-22  15:55                49 add.c
2014-10-22  15:55            21.582 add.dll
2014-10-21  15:02                93 ctest.c
2014-11-12  09:18            21.804 ctest.dll
               4 Datei(en),         43.528 Bytes
               2 Verzeichnis(se), 490.275.897.344 Bytes frei

D:\projects\C>copy *.dll ..\Java
add.dll
..\Java\add.dll überschreiben? (Ja/Nein/Alle): a
ctest.dll
        2 Datei(en) kopiert.

D:\projects\C>cd ..\Java

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  09:19    <DIR>          .
2014-11-12  09:19    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-10-22  15:44               216 HelloWorld$CTest.class
2014-10-22  15:44               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-23  13:19            17.286 objdump.txt
2014-10-23  11:46             3.819 sorted.txt
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              12 Datei(en),      1.035.607 Bytes
               2 Verzeichnis(se), 490.275.872.768 Bytes frei

D:\projects\Java>javac -classpath jna-3.2.5.jar HelloWorld.java

D:\projects\Java>java -classpath jna-3.2.5.jar:. HelloWorld
Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden

D:\projects\Java>

Open in new window

0
Duncan RoeSoftware DeveloperCommented:
I wouldn't trust "." in PATH. You never know what Java might be doing - it could have changed directory and only taken care of CLASSPATH. I would either explicitly add your folder to the PATH or copy ctest.dll to some folder already on the PATH (e.g. C\:\WINDOWS) (temporarily, of course;)
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Thank you for your help! I have done it and here is the result…

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Windows\system32>CD /D %PROJECTS%/Java

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  09:19    <DIR>          .
2014-11-12  09:19    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-23  13:19            17.286 objdump.txt
2014-10-23  11:46             3.819 sorted.txt
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              12 Datei(en),      1.035.607 Bytes
               2 Verzeichnis(se), 490.275.872.768 Bytes frei

D:\projects\Java>PATH
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Perform
ance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program F
iles (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL S
erver\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\M
anagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:
\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Java\jdk1.8
.0_05\bin;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\MinGW\bin;C:\
MinGW\mingw32\bin;.;c:\Program Files\Saxonica\SaxonHE9.4N\bin;D:\projects\Java

D:\projects\Java>PATH | FIND "D:\projects\Java"
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Perform
ance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program F
iles (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL S
erver\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\M
anagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:
\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Java\jdk1.8
.0_05\bin;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\MinGW\bin;C:\
MinGW\mingw32\bin;.;c:\Program Files\Saxonica\SaxonHE9.4N\bin;D:\projects\Java

D:\projects\Java>java jna-3.2.5.jar:. HelloWorld
Fehler: Hauptklasse jna-3.2.5.jar:. konnte nicht gefunden oder geladen werden

D:\projects\Java>java -classpath jna-3.2.5.jar:. HelloWorld
Fehler: Hauptklasse HelloWorld konnte nicht gefunden oder geladen werden

D:\projects\Java>

Open in new window

0
CEHJCommented:
D:\projects\Java>java jna-3.2.5.jar:. HelloWorld

Open in new window

is not a valid command in any way

D:\projects\Java>java -classpath jna-3.2.5.jar:. HelloWorld

Open in new window

Would be a valid command, but the path separator in Windows is the semicolon, not colon
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Here are the commands with a semicolon:

D:\projects\Java>java jna-3.2.5.jar;. HelloWorld
Fehler: Hauptklasse jna-3.2.5.jar;. konnte nicht gefunden oder geladen werden

D:\projects\Java>java -classpath jna-3.2.5.jar;. HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'ctest':
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at HelloWorld.main(HelloWorld.java:11)

D:\projects\Java>

Open in new window

0
CEHJCommented:
Well, i told you the first command was not valid in any way so putting in a semicolon was pointless ;)

Try the following

D:\projects\Java>java -Djava.library.path=. -classpath jna-3.2.5.jar;. HelloWorld

Open in new window


(that assumes ctest.dll is in that directory)
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Here you go!

D:\projects\Java>java -Djava.library.path=. -classpath jna-3.2.5.jar;. HelloWorl
d
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'ctest':
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at HelloWorld.main(HelloWorld.java:11)

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  09:19    <DIR>          .
2014-11-12  09:19    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-23  13:19            17.286 objdump.txt
2014-10-23  11:46             3.819 sorted.txt
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              12 Datei(en),      1.035.607 Bytes
               2 Verzeichnis(se), 490.275.872.768 Bytes frei

D:\projects\Java>

Open in new window

0
CEHJCommented:
Can you please post the code that handles ctest.dll?
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
D:\projects\Java>cd ..\C

D:\projects\C>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\C

2014-11-12  09:18    <DIR>          .
2014-11-12  09:18    <DIR>          ..
2014-10-22  15:55                49 add.c
2014-10-22  15:55            21.582 add.dll
2014-10-21  15:02                93 ctest.c
2014-11-12  09:18            21.804 ctest.dll
               4 Datei(en),         43.528 Bytes
               2 Verzeichnis(se), 490.275.872.768 Bytes frei

D:\projects\C>type ctest.c
/* ctest.c */

#include <stdio.h>

void helloFromC() {
    printf("Hello from C!\n");
}
D:\projects\C>gcc -o ctest.dll -shared ctest.c

D:\projects\C>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\C

2014-11-12  12:54    <DIR>          .
2014-11-12  12:54    <DIR>          ..
2014-10-22  15:55                49 add.c
2014-10-22  15:55            21.582 add.dll
2014-10-21  15:02                93 ctest.c
2014-11-12  12:54            21.804 ctest.dll
               4 Datei(en),         43.528 Bytes
               2 Verzeichnis(se), 490.275.872.768 Bytes frei

D:\projects\C>

Open in new window

ctest.c
0
CEHJCommented:
Actually i meant the Java code. Can i see that please?

Since the binary you're dealing with is in another directory, you would be better doing

D:\projects\Java>java -Djava.library.path=..\C -classpath jna-3.2.5.jar;. HelloWorld

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Yes, of course!

D:\projects\Java>java -Djava.library.path=..\C -classpath jna-3.2.5.jar;. HelloW
orld
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load librar
y 'ctest':
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:164)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:237)
        at com.sun.jna.Library$Handler.<init>(Library.java:140)
        at com.sun.jna.Native.loadLibrary(Native.java:375)
        at com.sun.jna.Native.loadLibrary(Native.java:360)
        at HelloWorld.main(HelloWorld.java:11)

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  12:59    <DIR>          .
2014-11-12  12:59    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              10 Datei(en),      1.014.502 Bytes
               2 Verzeichnis(se), 490.275.897.344 Bytes frei

D:\projects\Java>

Open in new window

HelloWorld.java
0
CEHJCommented:
It's conceivable it doesn't like relative paths and you could be missing a jar, so try (after getting those jars from https://github.com/twall/jna )

D:\projects\Java>java -Djna.library.path=D:\projects\C -classpath jna-4.1.0.jar;jna-platform-4.1.0.jar;. HelloWorld

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I never used jna-4.1.0.jar. I have jna-3.2.5.jar instead in the same directory, as you can see above.
0
CEHJCommented:
You didn't read my posting carefully enough:

so try (after getting those jars from https://github.com/twall/jna )
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
D:\projects\Java>java -Djava.library.path=..\C -classpath jna-platform-4.1.0.jar
;. HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Library
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at HelloWorld.main(HelloWorld.java:11)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 13 more

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  15:07    <DIR>          .
2014-11-12  15:07    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.478.925 Bytes
               2 Verzeichnis(se), 490.274.430.976 Bytes frei

D:\projects\Java>

Open in new window

0
CEHJCommented:
Again, you didn't read my posting carefully enough. That's not the command i gave you
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Sorry! I copied your comment you posted at 2014-11-12 at 14:16:07 now and got the following result:

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  15:07    <DIR>          .
2014-11-12  15:07    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.478.925 Bytes
               2 Verzeichnis(se), 490.274.430.976 Bytes frei

D:\projects\Java>java -Djna.library.path=D:\projects\C -classpath jna-4.1.0.jar;
jna-platform-4.1.0.jar;. HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Library
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at HelloWorld.main(HelloWorld.java:11)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 13 more

D:\projects\Java>

Open in new window

0
CEHJCommented:
Output, please, of

D:\projects\Java>jar tf jna-4.1.0.jar

Open in new window


?
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
D:\projects\Java>jar tf jna-4.1.0.jar
java.io.FileNotFoundException: jna-4.1.0.jar (Das System kann die angegebene Dat
ei nicht finden)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:220)
        at java.util.zip.ZipFile.<init>(ZipFile.java:150)
        at java.util.zip.ZipFile.<init>(ZipFile.java:121)
        at sun.tools.jar.Main.list(Main.java:1060)
        at sun.tools.jar.Main.run(Main.java:291)
        at sun.tools.jar.Main.main(Main.java:1233)

D:\projects\Java>DIR
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-12  15:07    <DIR>          .
2014-11-12  15:07    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-10-21  15:50           946.973 jna-3.2.5.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.478.925 Bytes
               2 Verzeichnis(se), 490.274.430.976 Bytes frei

D:\projects\Java>

Open in new window

0
CEHJCommented:
Again you didn't follow my instructions and get BOTH jars
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Sorry again! This time, a long list appears:

D:\projects\Java>jar tf jna-platform-4.1.0.jar
[…]
com/sun/jna/platform/win32/WinUser$WNDENUMPROC.class
com/sun/jna/platform/win32/WinUser$WindowProc.class
com/sun/jna/platform/win32/WinUser.class
com/sun/jna/platform/win32/Winioctl$STORAGE_DEVICE_NUMBER$ByReference.class
com/sun/jna/platform/win32/Winioctl$STORAGE_DEVICE_NUMBER.class
com/sun/jna/platform/win32/Winioctl.class
com/sun/jna/platform/win32/Winspool$PRINTER_INFO_1.class
com/sun/jna/platform/win32/Winspool$PRINTER_INFO_4.class
com/sun/jna/platform/win32/Winspool.class
com/sun/jna/platform/win32/WinspoolUtil.class
com/sun/jna/platform/win32/Winsvc$SC_HANDLE.class
com/sun/jna/platform/win32/Winsvc$SC_STATUS_TYPE.class
com/sun/jna/platform/win32/Winsvc$SERVICE_STATUS.class
com/sun/jna/platform/win32/Winsvc$SERVICE_STATUS_PROCESS.class
com/sun/jna/platform/win32/Winsvc.class
com/sun/jna/platform/win32/Wtsapi32.class
com/sun/jna/platform/win32/package.html
com/sun/jna/platform/wince/CoreDLL.class

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-13  13:39    <DIR>          .
2014-11-13  13:39    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              10 Datei(en),      1.531.952 Bytes
               2 Verzeichnis(se), 490.275.381.248 Bytes frei

D:\projects\Java>

Open in new window

0
CEHJCommented:
You are still not reading my replies properly, so you're wasting my time and yours. sae1962at, this is your LAST warning.
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
D:\projects\Java>java -Djna.library.path=D:\projects\C -classpath jna-4.1.0.jar;
 jna-platform-4.1.0.jar;. HelloWorld
Fehler: Hauptklasse jna-platform-4.1.0.jar;. konnte nicht gefunden oder geladen
werden

D:\projects\Java>dir
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-13  13:58    <DIR>          .
2014-11-13  13:58    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-11-13  13:58           914.597 jna-4.1.0.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.446.549 Bytes
               2 Verzeichnis(se), 490.274.463.744 Bytes frei

D:\projects\Java>

Open in new window

0
CEHJCommented:
D:\projects\Java>java -Djna.library.path=D:\projects\C -classpath jna-4.1.0.jar;jna-platform-4.1.0.jar;. HelloWorld

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Here, you go…
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Windows\system32>CD /D %PROJECTS%

D:\projects>cd Java

D:\projects\Java>DIR
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-13  14:03    <DIR>          .
2014-11-13  14:03    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-11-13  13:58           914.597 jna-4.1.0.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.446.549 Bytes
               2 Verzeichnis(se), 490.274.463.744 Bytes frei

D:\projects\Java>java -Djna.library.path=D:\projects\C -classpath jna-4.1.0.jar;
jna-platform-4.1.0.jar;. HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: %1 ist keine zulässig
e Win32-Anwendung.

        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.Native.open(Native.java:1759)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
        at com.sun.jna.Library$Handler.<init>(Library.java:147)
        at com.sun.jna.Native.loadLibrary(Native.java:412)
        at com.sun.jna.Native.loadLibrary(Native.java:391)
        at HelloWorld.main(HelloWorld.java:11)

D:\projects\Java>

Open in new window

0
CEHJCommented:
See http://de.kioskea.net/faq/1005-win-32-fehler-beheben#simili_main

Also you might need to recompile that dll and pay attention to the loading of 64/32 binaries
0
Duncan RoeSoftware DeveloperCommented:
Well here's a strange thing: I don't have Windows but I downloaded jna-4.10 to my Linux system. And everything you posted just worked!
21:03:09$ ls -l
total 12
-rw-r--r-- 1 dunc users 354 Nov 15 18:41 HelloWorld.java
-rw-r--r-- 1 dunc users 106 Nov 15 21:02 build
lrwxrwxrwx 1 dunc users  18 Nov 15 20:43 com -> /tmp/jna-4.1.0/com
-rw-r--r-- 1 dunc users  93 Nov 15 20:50 ctest.c
lrwxrwxrwx 1 dunc users  27 Nov 15 18:44 jna.jar -> /tmp/jna-4.1.0/dist/jna.jar
21:03:22$ cat build
javac -cp jna.jar HelloWorld.java 
gcc -shared ctest.c -o libctest.so
CLASSPATH=jna.jar:. java HelloWorld
21:04:16$ . build
Hello from C!

Open in new window

The FAQ at github says
set the system property jna.debug_load=true, and JNA will print its library search steps to the console.
jna.debug_load.jna will trace the search for JNA's own native support.
I would try this, but I don't know how to set system properties.

Actually I don't think I need the com symlink - that was an earlier attempt to compile HelloWorld.java.
0
CEHJCommented:
I would try this, but I don't know how to set system properties.

See THIS post
0
Duncan RoeSoftware DeveloperCommented:
Thanks for that. I tried it
00:44:28$ CLASSPATH=jna.jar:. java -Djna.debug_load.jna=true HelloWorld
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@139a55 for /com/sun/jna/linux-x86/libjnidispatch.so
Found library resource at jar:file:/tmp/jna-4.1.0/dist/jna.jar!/com/sun/jna/linux-x86/libjnidispatch.so
Trying /tmp/jna-3095046/jna36740228387306000.tmp
Found jnidispatch at /tmp/jna-3095046/jna36740228387306000.tmp
Hello from C!

Open in new window


The setting shows how java looks for the java class library but not how it looks for the native one. I was surprised that it found the native library, guess it looks along the class path.
Adding -Djna.library.path=. as you suggested in http:#a40399283 made no difference.
0
Duncan RoeSoftware DeveloperCommented:
Because this is Linux, I could use strace
01:23:22$ strace -e \!clock_gettime,sched_getaffinity,futex,gettimeofday,read,getdents64,close,rt_sigprocmask,mprotect,_llseek -f /bin/bash -c "CLASSPATH=jna.jar:. java HelloWorld" 2>t5
Hello from C!
01:26:26$ grep libctest t5
[pid  3467] open("/usr/lib/jdk1.8.0_25/jre/bin/../lib/i386/jli/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/jdk1.8.0_25/jre/bin/../lib/i386/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/tls/i686/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/tls/i686/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/tls/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/tls/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/i686/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/i686/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/tls/i686/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/tls/i686/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/tls/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/tls/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/i686/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/i686/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/sse2/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] stat64("/usr/lib/libctest.so", 0xb6756c4c) = -1 ENOENT (No such file or directory)
[pid  3467] stat64("/lib/libctest.so", 0xb6756c4c) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/jdk1.8.0_25/jre/bin/../lib/i386/jli/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/jdk1.8.0_25/jre/bin/../lib/i386/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/lib/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/tls/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] open("/usr/lib/libctest.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid  3467] stat64("/home/dunc/tests/ee130/linux-x86/libctest.so", 0xb675652c) = -1 ENOENT (No such file or directory)
[pid  3467] stat64("/home/dunc/tests/ee130/libctest.so", {st_mode=S_IFREG|0755, st_size=5548, ...}) = 0
[pid  3467] stat64("/home/dunc/tests/ee130/libctest.so", {st_mode=S_IFREG|0755, st_size=5548, ...}) = 0
[pid  3467] open("/home/dunc/tests/ee130/libctest.so", O_RDONLY|O_CLOEXEC) = 12

Open in new window

0
CEHJCommented:
-Djna.debug_load.jna=true -Djna.debug_load=true

Open in new window

is what i mentioned. Did you try both?
0
Duncan RoeSoftware DeveloperCommented:
No, I missed that. Thank you, it does give the required information
12:52:00$ CLASSPATH=jna.jar:. java -Djna.debug_load.jna=true -Djna.debug_load=true HelloWorld
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@139a55 for /com/sun/jna/linux-x86/libjnidispatch.so
Found library resource at jar:file:/tmp/jna-4.1.0/dist/jna.jar!/com/sun/jna/linux-x86/libjnidispatch.so
Trying /tmp/jna-3095046/jna2870883308526223124.tmp
Found jnidispatch at /tmp/jna-3095046/jna2870883308526223124.tmp
Looking for library 'ctest'
Adding paths from jna.library.path: null
Trying libctest.so
Adding system paths: [/usr/lib, /lib]
Trying libctest.so
Looking for version variants
Looking in classpath from sun.misc.Launcher$AppClassLoader@139a55 for ctest
Found library resource at file:/home/dunc/tests/ee130/libctest.so
Looking in /home/dunc/tests/ee130/libctest.so
Found library 'ctest' at /home/dunc/tests/ee130/libctest.so
Hello from C!

Open in new window

0
CEHJCommented:
Found library resource at jar:file:/tmp/jna-4.1.0/dist/jna.jar!/com/sun/jna/linux-x86/libjnidispatch.so

Open in new window

Funny - i thought binaries had to be in the file system ;)
0
Duncan RoeSoftware DeveloperCommented:
I don't understand your comment. /tmp/jna-4.1.0/dist/jna.jar is in the file system
0
CEHJCommented:
/tmp/jna-4.1.0/dist/jna.jar is in the file system
Yes, but the library is inside the jar, and therefore isn't
0
Duncan RoeSoftware DeveloperCommented:
That's why you can put either directories or jar files in CLASSPATH. As I understand it, at least
0
CEHJCommented:
It's probably a relatively new thing. I'm pretty certain that at one time, shared libraries HAD to be in the filesystem
0
Duncan RoeSoftware DeveloperCommented:
Could be ... Firefox complained my Java plugin was vulnerable so I installed JDK8u25
0
CEHJCommented:
Yes, that's important. Particularly now since Web Start supports the loading of native libraries (see above ;))
0
Duncan RoeSoftware DeveloperCommented:
I tried with JDK7u45 - same
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Your link gives information what the source for this problem could be, but not a precise answer.
0
CEHJCommented:
It think it might be a bitness issue. Try putting the library in SysWow64

http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm
0
krakatoaCommented:
Sorry - I can see I'm not being much help in this one. ;)
0
Duncan RoeSoftware DeveloperCommented:
@sae1962at - please rerun your test as you did in http:#40440106 but also including -Djna.debug_load.jna=true -Djna.debug_load=true as in http:#a40445151. In other words
java -Djna.library.path=D:\projects\C -Djna.debug_load.jna=true -Djna.debug_load=true -classpath jna-4.1.0.jar;jna-platform-4.1.0.jar;. HelloWorld

Open in new window


This should at least tell us what folders get searched.

You can paste the above line into a CMD window after you set the Quick Edit Mode Option (right-click title bar and select Properties then Options). After that, right-click pastes the clipboard contents to window; swipe to highlight a line then Enter puts the line on the clipboard.
This will save you having to try to re-type the line.
0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Hello, Duncan Roe! Here you go… :-)
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Windows\system32>CD /D %PROJECTS%

D:\projects>CD Java

D:\projects\Java>DIR
 Datenträger in Laufwerk D: ist Volume
 Volumeseriennummer: 0E8C-8BBC

 Verzeichnis von D:\projects\Java

2014-11-13  14:03    <DIR>          .
2014-11-13  14:03    <DIR>          ..
2014-10-22  15:55            21.582 add.dll
2014-11-12  09:18            21.804 ctest.dll
2014-11-12  09:23               216 HelloWorld$CTest.class
2014-11-12  09:23               495 HelloWorld.class
2014-10-22  12:20               354 HelloWorld.java
2014-11-13  13:58           914.597 jna-4.1.0.jar
2014-11-12  15:06         1.464.423 jna-platform-4.1.0.jar
2014-10-22  15:42            21.804 libctest.dll
2014-10-22  15:59               434 Test$Add.class
2014-10-22  15:59               508 Test.class
2014-10-22  16:01               332 Test.java
              11 Datei(en),      2.446.549 Bytes
               2 Verzeichnis(se), 490.274.463.744 Bytes frei

D:\projects\Java>java -Djna.library.path=D:\projects\C -Djna.debug_load.jna=true
 -Djna.debug_load=true -classpath jna-4.1.0.jar;jna-platform-4.1.0.jar;. HelloWo
rld
Trying (via loadLibrary) jnidispatch
Looking in classpath from sun.misc.Launcher$AppClassLoader@15db9742 for /com/sun
/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/D:/projects/Java/jna-4.1.0.jar!/com/sun/jna/
win32-x86-64/jnidispatch.dll
Trying C:\Users\saban\AppData\Local\Temp\jna-109191937\jna7120142846334052427.dl
l
Found jnidispatch at C:\Users\saban\AppData\Local\Temp\jna-109191937\jna71201428
46334052427.dll
Looking for library 'ctest'
Adding paths from jna.library.path: D:\projects\C
Trying D:\projects\C\ctest.dll
Adding system paths: []
Trying D:\projects\C\ctest.dll
Looking for lib- prefix
Trying libctest.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@15db9742 for ctest
Found library resource at file:/D:/projects/Java/ctest.dll
Looking in D:\projects\Java\ctest.dll
Exception in thread "main" java.lang.UnsatisfiedLinkError: %1 ist keine zulässig
e Win32-Anwendung.

        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.Native.open(Native.java:1759)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
        at com.sun.jna.Library$Handler.<init>(Library.java:147)
        at com.sun.jna.Native.loadLibrary(Native.java:412)
        at com.sun.jna.Native.loadLibrary(Native.java:391)
        at HelloWorld.main(HelloWorld.java:11)

D:\projects\Java>

Open in new window

0
krakatoaCommented:
"Keine zulaessige ..."

Not a permitted Windows32 application. In case another expert is short of a German dictionary.
0
Duncan RoeSoftware DeveloperCommented:
It looks  like it doesn't like the dll that you built with mingw. Please post your gcc command line.
It may be that 64-bit Java does not permit 32-bit DLL - as others have suggested earlier. You could try downloading 64-bit  mingw and build with gcc from that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Please also post the output of

java -version

Open in new window

0
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Trying to close this question...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.