cancel
Showing results for 
Search instead for 
Did you mean: 

JNI & MI 2.5

Former Member
0 Kudos

Hello,

I'm trying to call some native code from a MI application on WM2003 SE.

<b>[NOT MI]</b>

1. Created a JAVA wrapper application to call a native DLL (in NWDS, then executing javac, javah to create a header file)

2. Created the native DLL in embedded Visual C++ 4.0

3. Copied the native DLL and the JAVA wrapper app. to a mobile device

4. Started JAVA application (using Jrun from Creme 3.26)

5. Everything worked fine, the native functions were called.

<b>[MI]</b>

1. Added the JAVA wrapper class to a MI project

2. Deployed the MI project to the mobile device

3. When I try to call the native DLL from the servlet, I get an exception:

<i>java.lang.UnsatisfiedLinkError on <method_name> </i>

I think the problem is somewhere in the Tomcat server. I've tried to put the native dll in various directories (\Windows; \MI\bin\native etc.). I've also tried to set up java.library.path in MobileEngine.config:

<i>MI.ClientInstaller.StaticCommandLine=-Of -mi -classpath '%CI_HOME%/MICI.jar' com.sap.ip.mi.ci.ClientInstaller '-home:%CI_HOME%' -Djava.library.path=\windows

</i>

<i>MI.StaticCommandLine=-mi -Of -cf MI/creme_listOfJars.txt com.sap.ip.me.core.Startup '-home:%MI_HOME%' -Djava.library.path=\windows

</i>

Despite trying anything I could think about, I'm still experiencing the problem. Pls., can anyone help? Thanks in advance!

Regards,

Marek

P.S. Which version of the tomcat server is included in MI 2.5? I think it's the 3.3 version, but I'm not sure about this.

<b>JAVA wrapper class:</b>

public class NativeWrapper {
    static {
	System.loadLibrary("OrwNat");
    }

    public static native void Func1();
    public static native void Func2();
}

<b>Servlet class:</b>

public class MIInfoClass extends AbstractMEHttpServlet implements Constants {

...

public String doHandleEvent(
		String eventName,
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException, IOException {

...

    if (eventName.equals(EVENT_NAME_CALL)) {
        NativeWrapper.Func1();
	nextJSP = TABLEVIEW_JSP;
    }

...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hello marek,

try loading your DLL using

System.loadLibrary or

Runtime.getRuntime().loadLibrary

API prior to your invocation.

Please refer to their javadocs for details.

>Which version of the tomcat server is included in MI 2.5?

MI is using 3.2 version of Tomcat.

regards

jo

Former Member
0 Kudos

Thanks for the answer...

I've tried loading the library before invocation with both methods (System.loadLibrary; Runtime.getRuntime().loadLibrary), but I'm still getting the error.

Any other ideas?

Former Member
0 Kudos

The problem is not with the library itself. I think it's successfully loaded, because when I try to load some other library (e.g. loadLibrary("ImNotHere")) I get an error:

<i>java.lang.UnsatisfiedLinkError: no ImNotHere in shared library path

</i>

instead of:

<i>java.lang.UnsatisfiedLinkError on <method_name> </i>

So it seems like there is a problem with the method names. However, I don't understand why I'm able to call these methods from standard JAVA code (not MI)

Any ideas?

Thanks in advance!

Message was edited by: Marek Samaj

Former Member
0 Kudos

hello marek,

did you add the path to your library into the environment

variable PATH? if it is not found there, you will get

that UnsatisfiedLinkError.

Was the name you specified in the loadLibrary method the

same name with that of your library? e.g.

public class Jni {
  static {
    System.loadLibrary("Jni");
  }

  public native String whoiam();

  public static void main(String[] args) {
    Jni jni = new Jni();
    System.out.println(jni.whoiam());
  }
}

header name: Jni.h

so your Jni.dll location should be added into your

PATH env var.

regards

Jo

Former Member
0 Kudos

Hello Jo,

again, thank you very much for your time!

>did you add the path to your library into the environment

variable PATH?

I'm using this code on the Windows Mobile 2003 operating system. I don't know about any standard method to set the environment variables in this operating system. Despite this, I don't think that I have problem with the path. When I try to load some other library that I'm sure it doesn't exist, I get other error text with UnstatisfiedLinkError Exception (pls, see my previous post). Furthermore, I'm not expriencing any problems when using this DLL outside MI...

>Was the name you specified in the loadLibrary method the

same name with that of your library?

No! The name of the method is prefixed with: <i>Java_<className>_<methodName></i> in the library.

Former Member
0 Kudos

SOLVED!!!

The problem was with the method names, good suggestion Jo!

The methods must be prefixed with: Java_<b><package_name></b>_<className>_<methodName>

I had a default package in the notMI JAVA application, so there was no need of a package name in the C++ library.

However, in the MI app there was a package under which were the classes defined. This was the reason of the UnstatisfiedLinkError!

Regards,

Marek

Former Member
0 Kudos

Hi,

I'm with a problem in the DLL generation... I have been passed for this problem with package, on desktop tests, but i solved it... Now i'm trying run the DLL in the PPC 2003, the DLL is load, but the method into it is not found.

Java Code


package br.com.fiscalizacao.arcpad;

public class nativetest{

	static {
		System.loadLibrary("nativetest");
	}
	
	public native String sayHello(String x);
					     
	public native String SendScript(String x);
	
	public static void main(String[] argv)
	{
		
		nativetest nt = new nativetest();
		
		//Método 1
		String x = nt.sayHello("Access to DLL do with success.");		
		System.out.println(x);
	}
}

C Code


JNIEXPORT jstring JNICALL _Java_br_com_fiscalizacao_arcpad_nativetest_sayHello
  (JNIEnv *env, jobject thisobject, jstring js)

{
    return js;
}

Anyone?

Former Member
0 Kudos

hello fab,

are you getting java.lang.UnsatisfiedLinkError?

what are the messages you got?

jo

Former Member
0 Kudos

hi Jo, how are you?

Yes... the message is java.lang.UnsatisfiedLinkError...

Do you know what can be happened?

Is there any special mode to generate DLL to PPC 2003?

Former Member
0 Kudos

hello fab,

im just curious of the underscore prefix in

<b>_</b>Java_br_com_fiscalizacao_arcpad_nativetest_sayHello

can you try removing it...

any message you got for java.lang.UnsatisfiedLinkError like

<i>no method... </i> or loading specific?

jo

Former Member
0 Kudos

Jo,

I put this undescore because the virtual machine of CrEmE ask it... while i did the tests with the virtual machine of Java, wasn't need the undescore. But I already tried to take off, but continues the error...

The message is about the method.. The DLL is loaded with success...

Former Member
0 Kudos

What tool do you use to generate DLL for PPC 2003?

Former Member
0 Kudos

hello fab,

im using eVC4 and build my project for PPC2003 as target.

jo

Former Member
0 Kudos

Jo,

The DLLs that you generate, run without problems in PPC 2003 by JNI?

Thanks.

Former Member
0 Kudos

hello fab,

sorry i don't have ppc2003 device to test it...

though i had tried this way back 2yrs ago.

try removing your package and set them to default.

which creme version are you using?

jo

Former Member
0 Kudos

Jo,

The version is 3.25... The version of DLL for desktop (Win), is working with this package... no problems...

Now i need run the application in PPC 2003...

It's hard..

Former Member
0 Kudos

hello fab,

try compiling your dll with eVC for PPC2003...

regards

jo

Former Member
0 Kudos

Jo,

I'm using eVC... i go continue to try ... when i get work the DLL i send a message for you...

Thanks for your attention...

Former Member
0 Kudos

hi Jo.

i`m facing a problem with loading the dll ,

using Creme 4.10

the output i get in jscpout file is

java.lang.Unsatisfiedlinkerror : no Helloworld.dll in

java.library.path

and than the call stack.

i have tried copying it to \windows and in the \windows\creme\bin directory but with same error..

any idea about what can be the problem

thanks in advance

kapil

Answers (0)