Olá pessoal…
Seguindo minha linha de racioncínio, pensei em fazer minha applet fazer download das minhas bibliotecas (de acordo com o sistema operacional do cliente) de um servidor com endereço conhecido e instalá-las no cliente…Neste sentido, achei um código na internet que tem esses objetivos. O modifiquei para que ficasse mais adequado às minhas especificidades. O código é o seguinte:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package appletintalabibliotecas;
/**
* InstallApplet demonstrates the first step of the two-step application
* installation. It downloads the javatwain.dll to the lib/ext/x86 and the
* javatwain.jar to the lib/ext subdirectory of the clients JRE.
* In order to get access to the java.home system property, this applet has
* to be signed.
*/
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class AppletInstala extends JApplet
{
String javaHome=System.getProperty("java.home");
String osArch=System.getProperty("os.arch");
static String status1=null;
static String status2=null;
static String status3=null;
public void init()
{
super.init();
setLayout(new java.awt.BorderLayout());
this.setPreferredSize(new java.awt.Dimension(200,200));
//URL codeBase=this.getCodeBase();
try
{
URL url = new URL("http://200.233.17.240/testeAppletInstala/");
installFile(this,new URL(url, "libvlc.dll"), javaHome+"\\lib\\ext\\x86\\libvlc.dll");
}
catch (Exception exception)
{
System.out.println("Erro: "+exception+"");
exception.printStackTrace();
}
}
public void paint(Graphics g)
{
super.paint(g);
if (status1!=null)
{
g.drawString(status1,120,140);
g.drawString(status2,120,155);
}
if (status3!=null)
{
g.drawString(status3,120,170);
}
}
protected static void installFile(Applet applet, URL sourceUrl, String destFileName)
{
File destFile=new File(destFileName);
if (!destFile.exists())
{
try
{
System.err.println("installing file " + destFileName);
destFile.getParentFile().mkdirs();
URLConnection connection=sourceUrl.openConnection();
InputStream is=connection.getInputStream();
FileOutputStream fos=new FileOutputStream(destFile);
byte[] buff = new byte[8192];
BufferedInputStream in = new BufferedInputStream(is, buff.length);
BufferedOutputStream out = new BufferedOutputStream(fos, buff.length);
int i;
int count = 0;
while ((i = in.read(buff,0,buff.length)) != -1)
{ out.write(buff,0,i);
count += i;
}
applet.showStatus(count+" bytes copied ...");
in.close();
out.close();
status1="The javatwain library has been downloaded. To finish the" ;
status2="installation, you have to close the browser now. Reopen ";
status3="the browser to run the scanner application.";
}
catch (Exception exception)
{
exception.printStackTrace();
applet.showStatus(exception.toString());
}
}
else
{
System.err.println("file " + destFileName + " already exists");
status1="The javatwain library has been on your computer already";
status2="No installation is needed";
}
}
}
Assinei a applet, todavia, ela só funciona se for executada via appletviwer. Quando a executo a partir do browser, aparece o seguinte erro no meu console:
load: class appletintalabibliotecas.AppletInstala.class not found.
java.lang.ClassNotFoundException: appletintalabibliotecas.AppletInstala.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Anexei meu projeto neste post. Se alguém puder me ajudar nessa…