cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
kpant13
Level 3

Loading jnilib from inside a jar

Hi ,
I am having a simple question that when we add a jar file containing custom code in the installer then what is the path of this jar. I mean to say where does installer put this jar file.
Does installer put this jar file in IA_CLASSPATH?


Actually I want to load a jnilib. This jnilib is present inside a jar file along with other class files containing custom code . I am including this custom code jar in preinstall phase.

I am working on Mac os x. If I put this jnilib manually in java.library.path i.e
/System/Library/Java/Extension and use System.loadLibrary() then everything goes fine.But I can't put jar manually in java.library.path.

If I could know the path of my jar then I can better use System.load(path\to\my\lib).

OR
Is there any way to automatically put this jnilib inside
installer.app/contents/resources/java directiory while building the installer.

Any help would be highly appriciated.
-kpant
Labels (1)
0 Kudos
(4) Replies
kpant13
Level 3

Hi,
I have solved the problem.
I wrote a method to extract jni library from my jar and put it on System's tmpdir.
And it did the trick and load my library on launching the installer.
0 Kudos
TerryRidgway
Level 3

Can you post your solution for this? I'm having the same trouble. I was using some sample code from the IA2008 Training Manual, but it's not quite working correctly, even though it appears to get the right values for initial path.

Here's what I have that doesn't work:

try {
File dll = ip.saveURLContentToFile(
ip.getResource("NativeMessageBox.dll"));
System.load(dll.getAbsolutePath( ));
displayMessageBox( );
}
catch (IOException ioe)
{
javax.swing.JOptionPane.showMessageDialog(null, "Couldn't find the DLL!");
}

Thanks.
--Terry
0 Kudos
RobertDickau
Flexera Alumni

As a sanity check, is your DLL inside the custom class JAR file/zip file?
0 Kudos
TerryRidgway
Level 3

Hey Robert,

Yes, that's definitely something I've looked at. I've also checked the values generated by the getResource() call. The weird thing is that the value ends up with a ! character that I can't find in the actual path.

\InstallerData\Execute.zip!\

This really threw me for a loop and I concentrated on that ! character.

However, I just realized this morning that I was trying to use the JNI DLL that I'd compiled for a different Java class. So, silly me, I didn't have the right JNI header, or JNI method signature in the DLL, so even though it was reazlly loading the DLL correctly, it couldn't find the right method and was failing.

So, having said that, this means the code I posted earlier works fine, but you have to code up your Java class to use the right native method signature, like this:

public native boolean isAdminUser();

Then you have to run

"javah -jni -classpath %IA%/IAClasses.zip com.myclass.myAdminCheckClass"

That gives you a header file that you can include in the CPP file for your JNI DLL and you use the header file autogenerated method signature as your DLL entry point.


JNIEXPORT jboolean JNICALL Java_com_myclass_myAdminCheckClass_isAdminUser (JNIEnv *, jobject)
{
boolean bResult = true;
// Your code here
return bResult;
}

--Terry
0 Kudos