How to compile dynamic library for a JNI application on linux?

Native library can be loaded by loadLibrary with a valid name. By example, libXXXX.so for linux family, your hellolib.so should rename to libhello.so. By the way, I develop java with jni, I will separate the implementation and native interface (.c or .cpp). static { System.loadLibrary(“hello”); // will load libhello.so } The implementation header(HelloImpl.h): #ifndef _HELLO_IMPL_H … Read more

Javah tool error: Could not find class file for hellojni

I suspect the issue is that your class has a package and you are trying to run the command from the directory with the class file instead of the package root. Samhain’s example works because his MyClass.java contains no package, whereas I suspect yours does. For example, assume we have the following file at c:\src\com\example\MyClass.java … Read more

Managing DLL dependencies with Maven

Did you try something like this: <dependency> <groupId>com.foo</groupId> <artifactId>footron</artifactId> <version>4.2</version> <scope>runtime</scope> <type>dll</type> </dependency> You can add them to maven’s repository with something like this: mvn install:install-file -Dfile=footron.dll -DgroupId=com.foo -DartifactId=footron -Dversion=4.2 -Dpackaging=dll -DgeneratePom=true Haven’t done this for DLLs but something like this should work.

Pinning a Java application to the Windows 7 taskbar

I don’t have Windows 7 but here is something that might get you started: On the Java side: package com.stackoverflow.homework; public class MyApplication { static native boolean setAppUserModelID(); static { System.loadLibrary(“MyApplicationJNI”); setAppUserModelID(); } } And on the native side, in the source code of the `MyApplicationJNI.dll library: JNIEXPORT jboolean JNICALL Java_com_stackoverflow_homework_MyApplication_setAppUserModelID(JNIEnv* env) { LPCWSTR id … Read more

passing string array from java to C with JNI

You can write a simple function that takes a jobjectArray object, cast each one to jstring and then call GetStringUTFChars on it. Like this: void MyJNIFunction(JNIEnv *env, jobject object, jobjectArray stringArray) { int stringCount = env->GetArrayLength(stringArray); for (int i=0; i<stringCount; i++) { jstring string = (jstring) (env->GetObjectArrayElement(stringArray, i)); const char *rawString = env->GetStringUTFChars(string, 0); // … Read more

Passing a byte[] in Java to a function in C through JNI: how to use jarraybyte

you can get jbyte* by GetByteArrayElements: jbyte* bufferPtr = (*env)->GetByteArrayElements(env, array, NULL); And it is important to know the length of your array: jsize lengthOfArray = (*env)->GetArrayLength(env, array); Having jbyte* and length, you can do all the things in c-array. Finally, releasing it: (*env)->ReleaseByteArrayElements(env, array, bufferPtr, 0);

Calling C# code from Java?

You would use the Java Native Interface to call your C# code compiled into a DLL. If its a small amount of C#, it would be much easier to port it to Java. If its a lot, this might be a good way to do it. Here is a highlevel overview of it: http://en.wikipedia.org/wiki/Java_Native_Interface Your … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)