[jitsi-dev] JNA in Jitsi


#1

Hi,

Sorry for the novice question but I've never got really into Java programming.
I hope you can help me out.

I added this to PortAudioClipImpl.java:

import com.sun.jna.Library;
import com.sun.jna.Native;

class BeepMe {

    public interface Kernel32 extends Library {
       // FREQUENCY is expressed in hertz and ranges from 37 to 32767
       // DURATION is expressed in milliseconds
       public boolean Beep(int FREQUENCY, int DURATION);
       public void Sleep(int DURATION);
   }

    /**
     * @param args the command line arguments
     */
    public static void ringme() {
        // TODO code application logic here
        Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
        lib.Beep(698, 500);
        lib.Sleep(500);
        lib.Beep(698, 500);
    }
}

···

---

In
private void runInPlayThread()
I added a call to:
BeepMe.ringme();

When I debug the application I get this erorr message:

util.UtilActivator.uncaughtException().88 An uncaught exception occurred in thread=Thread[Thread-72,10,main] and message was: com/sun/jna/Library
java.lang.NoClassDefFoundError: com/sun/jna/Library
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
  at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
  at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.findClass(ModuleImpl.java:1947)
  at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:752)
  at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)
  at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1807)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  at net.java.sip.communicator.impl.neomedia.notify.BeepMe.ringme(PortAudioClipImpl.java:36)
  at net.java.sip.communicator.impl.neomedia.notify.PortAudioClipImpl.runInPlayThread(PortAudioClipImpl.java:192)
  at net.java.sip.communicator.impl.neomedia.notify.PortAudioClipImpl.access$000(PortAudioClipImpl.java:49)
  at net.java.sip.communicator.impl.neomedia.notify.PortAudioClipImpl$1.run(PortAudioClipImpl.java:95)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library not found by [19]

How can I fix this?
Why can't it find com.sun.jna.Library?
It didn't complain when it compiled.

I tried adding jna.jar to "Tools->Libraries" in Netbeans but had the same issue.

Just for the record, I started a plain Netbeans project with the following code and it compiled and ran correctly (I hear the speaker beep):

package jnabeeptest;

import com.sun.jna.Library;
import com.sun.jna.Native;

public class JNAbeeptest {

    public interface Kernel32 extends Library {
       // FREQUENCY is expressed in hertz and ranges from 37 to 32767
       // DURATION is expressed in milliseconds
       public boolean Beep(int FREQUENCY, int DURATION);
       public void Sleep(int DURATION);
   }

    public static void main(String[] args) {
        Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
        lib.Beep(698, 500);
        lib.Sleep(500);
        lib.Beep(698, 500);
    }
}

The only thing I did was add a library and pointed to:

jitsi\lib\os-specific\windows\installer-exclude\jna.jar

So what's wrong with the JNA code I'm trying to run within Jitsi?

Thanks,

Vieri


#2

На 24 април 2012, 20:27, Vieri <rentorbuy@yahoo.com> написа:

java.lang.NoClassDefFoundError: com/sun/jna/Library

Add com.sun.jna to the Import-Package list in
src/net/java/sip/communicator/impl/neomedia/neomedia.manifest.mf i.e.
the manifest of the OSGi bundle in which you want to use the package.


#3

Thanks Lyubomir!
That worked.

Vieri

···

--- On Tue, 4/24/12, Lyubomir Marinov <lubo@jitsi.org> wrote:

> java.lang.NoClassDefFoundError: com/sun/jna/Library

Add com.sun.jna to the Import-Package list in
src/net/java/sip/communicator/impl/neomedia/neomedia.manifest.mf
i.e.
the manifest of the OSGi bundle in which you want to use the
package.