jna ライブラリを使用して印刷するアプレットを作成しました。実行すると、java.lang.reflect.InvocationTargetException という例外が発生します。Java コンソールを見ると、例外はありません。
Java Plug-in 10.4.1.255
Using JRE version 1.7.0_04-b22 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Administrator
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
私のソースコード:
import com.sun.jna.Native;
import java.applet.Applet;
class Impressora extends Applet {
@Override
public void init() {
try {
Mp2032 lib = (Mp2032) Native.loadLibrary("mp2032", Mp2032.class);
System.out.println(lib.IniciaPorta("COM3"));
System.out.println(lib.ConfiguraModeloImpressora(5));
System.out.println(lib.BematechTX("teste\n"));
System.out.println(lib.BematechTX("teste\n"));
System.out.println(lib.AcionaGuilhotina(1));
System.out.println(lib.FechaPorta());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import com.sun.jna.Library;
import com.sun.jna.win32.StdCallLibrary;
public interface Mp2032 extends StdCallLibrary {
public int AcionaGuilhotina(int modo);
public int AjustaLarguraPapel(int largura);
public int AutenticaDoc(String texto, int tempo);
public int BematechTX(String texto);
public int CaracterGrafico(String texto, int lenght);
public int ComandoTX(String comando, int length);
public int ConfiguraCodigoBarras(int altura, int largura, int posicao, int fonte, int margem);
public int ConfiguraModeloImpressora(int modelo);
public int IniciaPorta(String porta);
public int FechaPorta();
public int FormataTX(String texto, int tipoLetra, int italico, int sublinahdo, int expandido, int enfatizado);
}
私のindex.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<applet width=300 height=300 code="Impressora" ARCHIVE="ImpressoraAssinada.jar"></applet>
</div>
</body>
</html>
私のキー生成:
cd C:\path\to\dir\Impressora
keytool -genkey -dname "cn=Impressora, ou=XX, o=XXX, l=city, s=RS c=BR" -alias ImpressoraKey -keystore C:\ImpressoraKey -storepass passwd -validity 7300
jarsigner -keystore C:\ImpressoraKey -storepass passwd -signedjar ImpressoraAssinada.jar Impressora.jar ImpressoraKey
keytool -export -keystore C:\ImpressoraKey -storepass passwd -alias ImpressoraKey -file Impressora.x509