This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallAnywhere
- :
- InstallAnywhere Forum
- :
- Loading jnilib from inside a jar
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Oct 30, 2008
09:10 AM
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
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
(4) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Nov 04, 2008
07:08 AM
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.
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Nov 14, 2008
06:13 PM
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
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
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Nov 17, 2008
09:52 AM
As a sanity check, is your DLL inside the custom class JAR file/zip file?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Nov 17, 2008
01:15 PM
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
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.
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
