Pessoal preciso acessar umas DLL’s nativas através do Browser, então nós decidimos usar Applets e JNA. Aí que vem o problema, quando eu executo o JNA na IDE ou mesmo em linha de comando, roda perfeitamente bem, mas quando ponho no applet ele lança umas exceções:
Exception in thread “thread applet-br.sis.Teste.Applet.TesteApplet-1” java.lang.NoClassDefFoundError: com/sun/jna/win32/StdCallLibrary
Caused by: java.lang.ClassNotFoundException: com.sun.jna.win32.StdCallLibrary
Eu não sei acontece isso, se meu path já tem a jna.jar, e ainda por cima, roda normalmente sem o applet!
E ah, peguem leve cmg, é a primeira vez que uso JNA e Applet… hehehhee
Aqui vai o código do JNLP:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>AppletJNA</title>
<vendor>Hedley Luna</vendor>
</information>
<security>
<j2ee-application-client-permissions/>
</security>
<resources>
<!-- Application Resources -->
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se" />
<jar href="C:\Users\Hedley\Desktop\testerepositorioMercurial\TesteJNA\src\br\sis\Teste\Applet\TesteJNA.jar" main="true" />
<jar href="https://jna.dev.java.net/source/browse/*checkout*/jna/tags/3.2.4/jnalib/dist/jna.jar" />
</resources>
<applet-desc
name="TesteApplet"
main-class="br.sis.Teste.Applet.TesteApplet"
width="300"
height="300">
</applet-desc>
<update check="background"/>
</jnlp>
Aqui o html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Teste</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<h1>Teste</h1>
<applet code = 'br.sis.Teste.Applet.TesteApplet'
jnlp_href = 'TesteJNA.jnlp',
width = 300,
height = 300 />
</body>
</html>
E aqui o codigo do applet:
public void init() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
JLabel lbl = new JLabel();
Ikernel32 lib =
(Ikernel32) Native.loadLibrary("kernel32", Ikernel32.class);
DataHoraSistema time = new DataHoraSistema();
lib.GetSystemTime(time);
lbl.setText(String.valueOf(time.wDay));
add(lbl);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
});
}