NetBeans Development 7 - Windows 7 64-bit ... Native JNI Calls ... How to Manage

I give you this, hopefully saves you time and pain.

As part of my experience with NB Development v7 on my 64-bit Windows workstation, I found another disappointing adventure in an attempt to get the JNI (Java Native Interface) capabilities and work in my project. Thus, I include a brief description of the necessary steps (since all the documentation I found was completely incorrect for these versions of Windows and NetBeans on how to make JNI). It took several days of experimentation and a review of every web page I could find that included these technologies in a keyword search. Yuk !! Not fun.

For starters, since NetBeans Development is "all about modules", if you read this, you may need one or more modules to make JNI calls. Most of what is available on this site or on the Internet as a whole (not to mention the help file in NB7) is either completely incorrect for these versions, or so rare that it is essentially not used by anyone other than the JNI expert.

Here's what you are looking for ... "cut the chase" - "how to drive" to get a JNI call and work with your 64-bit NB7 / Windows field.

1) From within the NetBeans module (and not the host application), declare your own method and make sure that you can compile the Java source without errors.

Example:

package org.mycompanyname.nativelogic;

    public class NativeInterfaceTest
    {
        static
        {
            try
            {
                if (System.getProperty( "os.arch" ).toLowerCase().equals( "amd64" ) )
                    System.loadLibrary( <64-bit_folder_name_on_file_system>/<file_name.dll> );
                else
                    System.loadLibrary( <32-bit_folder_name_on_file_system>/<file_name.dll> );
            }
            catch (SecurityException se) {}
            catch (UnsatisfieldLinkError ule) {}
            catch (NullPointerException npe) {}
        }

        public NativeInterfaceTest() {}

        native String echoString(String s);
    }

, ( ), , . ( ) "echoString". , C/++, JNI Java.

2) 64- Windows ( ), 64- Visual Studio ( 32- ) "vcvarsall" BAT, "amd64", 64- .

:

<path_to_Microsoft_Visual_Studio_10.0>/VC/vcvarsall.bat amd64

, C/++ Microsoft. ​​Visual Studio 2005, 2008 2010, "v10.0", , 64- , . "amd64".

3) \ , , .

: - "org.mycompanyname.nativelogic.NativeInterfaceTest". Java 1 , NetBeans :

"////MyCompanyName/nativelogic/NativeInterfaceTest.class"

, , , "/build/classes" - .

4) C/++, JNI. :

javah -jni org.mycompanyname.nativelogic.NativeInterfaceTest enter. - , , , , Windows PATH ( /bin ). , PATH , .

"org_mycompanyname_nativelogic_NativeInterfaceTest.h"... C. , .

5) NativeInterfaceTest.h echoString().

:

JNIEXPORT jstring JNICALL Java_org_mycompanyname_nativelogic_NativeInterfaceTest_echoString
  (JNIEnv *env, jobject jobj, jstring js)
{
    return((*env)->NewStringUTF(env, "My JNI is up and working after lots of research"));
}

, Java ( C). JVM Java , . - Oracle JNI.

6) . , Header, ".h" ".c", C, JNI.

: NativeInterfaceTest.c

7) . :

cl/I "path_to_my_jdks_include_folder" /I "path_to_my_jdks_include_win32_folder" /D: AMD64 = 1/LD NativeInterfaceTest.c/FeNativeInterfaceTest.dll/link/machine: x64

:

cl /I"D:/Program Files/Java/jdk1.6.0_21/include" /I"D:/Program Files/java/jdk1.6.0_21/include/win32" /D:AMD64=1 /LD NativeInterfaceTest.c /FeNativeInterfaceTest.dll /link /machine:x64

, "include" "include/win32" , ... "Program Files". , , , .

, DLL, . , Java. System.loadLirbary().

8) ! . DLL :

<path_of_NetBeansProjects_folder>/<project_name>/<module_name>/build/cluster/modules/lib/x64

, , , "lib" "x64".

Example:
C:\Users\<user_name>\Documents\NetBeansProjects\<application_name>\<module_name>\build\cluster\modules\lib\x64\NativeInterfaceTest.dll

Java... , .dll loadLibrary()?

System.loadLibrary( "/x64/NativeInterfaceTest" );

, Java NativeInterfaceTest echoString(), String, NativeInterfaceTest.c.

, , , . !

+5
1

, -, - , -:

32/64 DLL.

if (System.getProperty( "os.arch" ).toLowerCase().equals( "amd64" ) )
   System.loadLibrary( <64-bit_folder_name_on_file_system>/<file_name.dll> );
else
   System.loadLibrary( <32-bit_folder_name_on_file_system>/<file_name.dll

:

String archDataModel = System.getProperty("sun.arch.data.model");
System.loadLibrary("dllName" + archDataModel);

dllName32.dll dllName64.dll .

... .

+2

All Articles