Meaningless Drivel is fun!*
The moose likes IDEs, Version Control and other tools and the fly likes Unsatisfied link error in NetBeans but not from browser or command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Unsatisfied link error in NetBeans but not from browser or command line" Watch "Unsatisfied link error in NetBeans but not from browser or command line" New topic
Author

Unsatisfied link error in NetBeans but not from browser or command line

pete western
Greenhorn

Joined: May 27, 2009
Posts: 4
Hello All

Can someone please give me some guidance here?
I am trying to get some java code working in NetBeans 6.1 (platform is JDK 1.6.0_13 - latest I think). The code is a sample from ACS for their ACR122U NFC smart card reader.

If I use a browser (IE7 - same JDK version) - the sample applet all works fine.
I can also use command line ("java <app>.class") and it works fine too

BUT

If I use the corresponding sources and build a NetBeans 6.1 project - they cease working. There is a link error:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: activesample.JacspcscLoader.SCardEstablishContext(IIII)I
at activesample.JacspcscLoader.SCardEstablishContext(Native Method)
at activesample.JacspcscLoader.jSCardEstablishContext(JacspcscLoader.java:31)
at activesample.ActiveSample.actionPerformed(ActiveSample.java:191)



I have the JacspcscLoader.java source file - this has a static System.LoadLibrary call in it..:

static {
System.loadLibrary("Jacspcsc");
}


...and it also declares all the native methods, e.g.

public int jSCardEstablishContext(int dwscope, int pvReserved1, int pvReserved2, int [] phContext)
{
ret = SCardEstablishContext(dwscope, pvReserved1, pvReserved2, hContext);
phContext[0] = hContext; //return value of hContext;
return ret;
};



The Jacspcsc.dll is present and on the path. It is the latest version from the supplier and is in WINDOWS/System32 which is on the path - this is the only instance of the dll on the system.
So, it is found and loaded ok. And must be working ok for the browser command line versions to work properly.

BUT, it will not work with NetBeans !!

Any ideas why it is ok from the browser applet, or from the command line but NOT from NetBeans? Is there some bizarre thread, sharing, minutiae, detail that needs to be tinkered with or something more simple perhaps???

The only thing I did to JacspcscLoader (wrapper file) was to add it to the same package as the application by adding the line "package activeSample;". Has this introduced a scope issue or is that a red herring....?

All help very welcome indeed.

Does anyone have any alternate suggestions to get up an running (I think I just need a PC/SC stack to call from java...?)

With many thanks

Cheers

Pete
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Pete and welcome to Javaranch!

I'm going to move this to the IDEs forum where hopefully you'll get the specialised help you need

As an aside does your version of Netbeans officially support JDK 1.6? Does it use 1.6 settings by default for projects that you run within Netbeans?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
pete western
Greenhorn

Joined: May 27, 2009
Posts: 4
Hello Martijn

Thank you for the reply and your welcome message! :-)

To be honest, I do not really know the answer to your question. I >assume< it supports JDK 1.6. I had previously installed V5.5 and that was using JDK 1.5xxx Then I "upgraded" to the new version (at the time V6.1) and at the same time upgraded my java installation to 1.6.0_7. More recently I have upgraded to the latest java 1.6.0_13-b03.

If I use "help/about" in NetBeans it says "Java 1.6.0_7".

Thank you for your interest

Kind regards

Pete

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

This might be a wild stab in the dark, but have you considered moving to Netbeans 6.5.1? I think that's the latest stable version.
pete western
Greenhorn

Joined: May 27, 2009
Posts: 4
Hello Martin

I upgraded to NetBeans 6.5.1 and to Java 1.6.0_13 and I rebuilt everything - still the same problem - Unsatisfied link error. :-(

If no-one has any clues for this problem, then perhaps someone knows an alternative PC/SC stack for java that works within NetBeans?

Kind regards

Pete
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5811
    
    7

A few possibilities:

Are you running NetBeans with a 32-bit or 64-bit JDK? If with a 64-bit JDK, then you will not be able to load the Jacspcsc.dll, which I presume is 32-bit.

Look at the netbeans_home/etc/netbeans.conf file to see if the java.library.path is set. You could even try adding "-J-Djava.library.path=xxx" to netbeans_default_options (where "xxx" is the value of PATH).


JBoss In Action
pete western
Greenhorn

Joined: May 27, 2009
Posts: 4
Hello All

Thank you for your help and comments.
Embarrassingly, this turned out to be a JNI type issue. With my lack of experience of NetBeans I overlooked the obvious i.e. that I had structured the app as a single package with 3 source files. I had added "package x;" to each to make it build easily in a single project.

However, this meant that the method reference was now "Java_x_JacspcscLoader_methodName" - obviously the additional "_x" had messed up the runtime link. (needless to say there was no good DLL documentation that migh have made this error more obvious sooner but many thanks to a utility from UCWare.com that helpfully lists the DLL exports :-)

I have now created a separate library in a .jar file without the additional package name, and referenced this library from the application. It is all fine now.

Thank you for the support you guys have offered it was great to know there are people out there willing to help with other peoples problems!

Thank you very much

Cheers!

Pete
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Glad to help! Sometimes you need to bounce questions off people to realise that you're walking down the wrong path
Michael Angelo Wong
Greenhorn

Joined: Jan 20, 2010
Posts: 1
....
The Jacspcsc.dll is present and on the path. It is the latest version from the supplier and is in WINDOWS/System32 which is on the path - this is the only instance of the dll on the system.
So, it is found and loaded ok. And must be working ok for the browser command line versions to work properly.

.....

hi pete, I'm Michael From Philippines. I, too, am developing a smartcard project using the ACR122U NFC smart card reader from ACS HK. I was wondering if your SDK already contain the "Jacspcsc.dll" or were you able to download it from ACS website? I can't find the said .dll after I install the SDKs, Driver, Soure Codes, everything in my PC.

I would really appreciate your help. This would be my first Smartcard project.

Michael
Bart Bartus
Greenhorn

Joined: May 16, 2010
Posts: 1
Hi Pete,

Perhaps you can help me out with the solution described by yourself. I have created a new project and included the ACSModule.java and JacspcscLoader.java. I have not placed these files in a pacakage. A jar file is constructed with the class files in the root of the jar file. When I add this jar to my project, I´m using Netbeans so right click and add JAR/File allows me to add the jar file to the project as library.

But as soon as I try to import the jar file which I've named 'JacpcscLoader' through an import statement it says that the package does not exist. Can you tell me how you constructed your jar file? Could you determine a possible cause of why at import Netbeans does not seem to be able to find the package?

Many many thanks in advance for your help!

Cheers,

Bart

pete western wrote:I have now created a separate library in a .jar file without the additional package name, and referenced this library from the application. It is all fine now.
Joanne Castillo
Greenhorn

Joined: Feb 04, 2010
Posts: 1
Hello,

I am not sure if you already figured this out but just to answer your query:

The applet that was working was compiled prior to distribution so it would basically work since all the components needed are compiled according to how it was coded.

You encounter the Unsatisfied Link Error because the application your created classes cannot locate the methods in the jacspcsc.dll file. This is because the jacspcsc.dll was developed assuming that all the methods that will call it will be placed in the default package (meaning, the java classes are not contained in any particular class), therefore, placing your java classes that calls the methods in the wrapper in a particular package will occur in an error because the wrapper is assumed to be in the default package. If you want your java classes to be placed in a particular package, re-compilation of the jacspcsc.dll is needed. In this case, you need to contact ACS so that their developers could attend to this and give you a library based on your specifications. Another option is to create your own wrapper library for the winscard library.

For further assistance, do contact ACS.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unsatisfied link error in NetBeans but not from browser or command line
 
Similar Threads
Using DLL in Java
.WAR not unpacking
method not found in imported class - JCAPS6
WAS 6.1 JMX AdminClient.
Can't get the result of factorial method