applet引用jar中的dll文件

把一个开源项目ocf打成jar包后,想把它作为applet插件运行于浏览器,但打成的jar要引用一个dll文件,而applet又不能访问服务器资源,所以就在ocf工程中加上了一段在本机创建dll文件的程序,但ocf中引用dll文件的对象为静态对象,所以把新建的文件也命名成静态的,否则运行时会出现文件被其他程序占用的异常。

主要代码如下:

 static FileOutputStream fos = null;
  static DataOutputStream dos = null;
  static File file=null;

static public void loadLib() {
    try {

          byte[] buf = new byte[2048];
  file = new File("d:/ocfpcsc2.dll");
  if(file.exists()==false){

 file.createNewFile();
   fos = new FileOutputStream(file);
   dos = new DataOutputStream(fos);
   InputStream in = OCFPCSC1.class.getResourceAsStream("ocfpcsc1.dll");
   DataInputStream  dis = new DataInputStream(new BufferedInputStream(in));

while(dis.read(buf)!=-1){
    dos.write(buf,0,buf.length);
   }
   in.close();
   fos.flush();
   fos.close();
   dos.flush();
   dos.close();

opencard.core.util.SystemAccess.getSystemAccess().loadLibrary("d:/ocfpcsc2.dll");

  } catch (Exception e) {
      e.printStackTrace();
    }
  }

 

SystemAccess.java

 public static SystemAccess getSystemAccess() {
    SystemAccess sys = _registeredSystems.get(Thread.currentThread());
    if (sys==null)
      return _theSystem;
    else return sys; 
  }

/**
 * Link to a native DLL.
 */
  public void loadLibrary(String libName) {
    //System.out.println("using SystemAccess.loadLibrary()");
   //System.loadLibrary(libName);
  
  System.load(libName);
  }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
javacard applet 开发实例 正常运行 带jar包 package mifare; import com.ibm.jz.JZSystem; import javacard.framework.APDU; import javacard.framework.Applet; import javacard.framework.ISO7816; import javacard.framework.ISOException; import javacard.framework.Util; public class AmbiqApplet extends Applet { byte[] mifarePassDefault={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass8={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] mifarePass9={(byte)0x0b,(byte)0x54,(byte)0x57,(byte)0x07,(byte)0x45,(byte)0xfe,(byte)0x3a,(byte)0xe7}; byte[] adminPass={(byte)0x40,(byte)0x41,(byte)0x42,(byte)0x43,(byte)0x44,(byte)0x45,(byte)0x46,(byte)0x47,(byte)0x48,(byte)0x49,(byte)0x4a,(byte)0x4b,(byte)0x4c,(byte)0x4d,(byte)0x4e,(byte)0x4f}; public static void install(byte[] bArray, short bOffset, byte bLength) { // GP-compliant JavaCard applet registration new AmbiqApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]); } public void process(APDU apdu) { short i; byte[] send=new byte[52]; byte[] send2=new byte[24]; // Good practice: Return 9000 on SELECT if (selectingApplet()) { return; } byte[] buf = apdu.getBuffer(); if(buf[ISO7816.OFFSET_CLA]==AmbiqConstant.CLS_AMBIQ) { switch (buf[ISO7816.OFFSET_INS]) { case AmbiqConstant.INS_GET_MIFARE: if(buf[ISO7816.OFFSET_P1]!=0 || buf[ISO7816.OFFSET_P2]!=0) { ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); return; } /*Get Entire Mifare Ticket data * Returns back the content of the entire sector 8 (3 block 8.0, 8.1, 8.2) and the first 4 bytes of block 9.0; total 52bytes. Filed Length (in bytes) Data Comments CLA 1 0x80 Fixed class for the applet INS 1 0x20 Read entire data P1 1 0x00 Sector number P2 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值