Pessoal,
Será que alguem pode me dá uma dica de como resolver isso?
Exception in thread "Timer-0" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:217)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:88)
at httpclient.Acesso.Apaga(Acesso.java:101)
at httpclient.Acesso$1.run(Acesso.java:164)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at sun.misc.Launcher$ExtClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
eu tenho um codigo que eu rodo ele no NetBeans e não dá erro nenhum, executa. Referenciei as seguinte bibliotecas:
commons-httpclient-3.0.1.jar
commons-codec-1.4.jar
commons-codec-1.4-sources.jar
commons-codec-1.4-javadoc.jar
commons-logging-api-1.0.2.jar
Mas quando eu gero o arquivo .Jar, que foi criado seguindo essa dica, http://preclog.blogspot.com/2010/03/criando-jar-no-netbeans-sem-pasta-lib.html , para que todas as dependencias fossem criandas juntas, aparece o erro acima.
segue o codigo:
package impressao;
import java.awt.*;
import java.awt.print.*;
import java.io.*;
import java.net.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class Acesso implements Printable {
//cria as variaveis de fontes
public static final int DEFAULT_FONT_SIZE = 12;
public static final String DEFAULT_FONT_NAME = "Serif";
//impressora
private PrinterJob job;
private String typeName;
private int typeSize;
private Font typeFont;
private Font typeFontBold;
private String [] header;
private String [] body;
public Acesso() {
this(DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE);
}
public Acesso(String name, int size)
{
if (size < 3 || size > 127) {
throw new IllegalArgumentException("Type size out of range");
}
typeName = name;
typeSize = size;
typeFont = new Font(typeName, Font.PLAIN, typeSize);
typeFontBold = new Font(typeName, Font.BOLD, typeSize);
job = null;
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
FontMetrics fm;
graphics.setFont(typeFont);
graphics.setColor(Color.black);
fm = graphics.getFontMetrics();
int i;
double x, y;
x = pageFormat.getImageableX();
y = pageFormat.getImageableY() + fm.getMaxAscent();
// Cria cabeçalho
if (header != null) {
graphics.setFont(typeFontBold);
for(i = 0; i < header.length; i++) {
graphics.drawString(header[i],(int)x, (int)y);
y += fm.getHeight();
}
}
// parte da impressão
if (body != null) {
graphics.setFont(typeFont);
for(i = 0; i < body.length; i++) {
graphics.drawString(body[i],(int)x,(int)y);
y += fm.getHeight();
}
}
return PAGE_EXISTS;
}
protected void init() {
job = PrinterJob.getPrinterJob();
}
public int getCharsPerLine() {
if (job == null) {
init();
}
PageFormat pf;
pf = job.defaultPage();
double width = pf.getImageableWidth();
double ptsize = typeFont.getSize();
double ptwid = ptsize * 3 / 4;
double cnt = (width / ptwid);
return (int)(Math.round(cnt));
}
public void Apaga() throws IOException{
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("http://192.168.0.1/academico/desenvolve/fotos/delete_dados.php");
int executeMethod = client.executeMethod(method);
}
public boolean doPrint(String [] header, String [] body, boolean interactive)
throws PrinterException
{
if (job == null) {
init();
}
if (interactive) try {
if (job.printDialog()) {
} else {
return false;
}
} catch (Exception pe) {
System.err.println("Não abriu a a janela de dialogo da impressora");
// assume user wants to print anyway...
}
job.setPrintable(this);
this.header = header;
this.body = body;
job.print();
job = null;
return true;
}
public static final long TEMPO = (100 * 60);
public static void main(String[] args) throws IOException {
final java.util.List lines;
final Acesso tp = new Acesso();
final Acesso ap = new Acesso();
lines = new java.util.ArrayList();
Timer timer = null;
if (timer == null) {
timer = new Timer();
TimerTask tarefa = new TimerTask() {
public void run() {
try{
URL amplus = new URL("http://192.168.0.1/academico/desenvolve/fotos/dados.txt");
URLConnection amp = amplus.openConnection();
amp.setConnectTimeout(7000);
amp.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(amp.getInputStream()));
String line;
for(line = in.readLine(); line != null;
line = in.readLine())
{
lines.add(line);
}
in.close();
String [] headers = new String[1];
headers[0] = "Impressão Biblioteca";
String [] body = new String[lines.size()];
for(int ix = 0; ix < lines.size(); ix++) {
body[ix] = (String)(lines.get(ix));
}
ap.Apaga();
try {
if(lines.isEmpty()){
}else{
boolean didit = tp.doPrint(headers, body, false);
lines.clear();
}
} catch (PrinterException ex) {
Logger.getLogger(Acesso.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MalformedURLException me) {
// System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
//System.out.println("IOException:1" + ioe);
}
} //fechou run
}; // fechou TimerTask
timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);
}
}
}
Agradeço qualquer ajuda.
Antonio