0
I made an application that has a timer to look in a certain directory of 2 in 2 seconds, well when I am running the application in Netbeans it works normally, but I tried to create a JAR of this application and it is not running in the application manager, if you have any idea what may be happening or how to create an executable of this application who knows.
Grateful
//<editor-fold defaultstate="collapsed" desc="IMPORTAÇÕES">
//import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.ini4j.Ini;
import org.ini4j.IniPreferences;
import org.ini4j.InvalidFileFormatException;
//</editor-fold>
public class LeituraPDF_Filtro_Validacao_FINAL_02 {
public static final long TEMPO = (25 * 60); // TIMER DE REPETIÇÃO DA APLICAÇÃO
public static void main(String args[]) throws InvalidFileFormatException, IOException {
System.out.println("inicio");
Timer timer = null;
if (timer == null) {
timer = new Timer();
TimerTask tarefa = new TimerTask() {
public void run() {
try {
//<editor-fold defaultstate="collapsed" desc="CARRREGAR ARQUIVO *.INI DE CONFIGURAÇÕES DE CAMINHOS DE ACESSO">
Ini ini = new Ini(new File("C:\\Embratec_Slips\\Em Processamento\\configHSS.ini"));
java.util.prefs.Preferences prefs = new IniPreferences(ini);
String inPath = prefs.node("cfg").get("inPath", "null").split(";")[0].trim();
String outPath = prefs.node("cfg").get("outPath", "null").split(";")[0].trim();
String inProcess = prefs.node("cfg").get("inProcess", "null").split(";")[0].trim();
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="DIRETÓRIO DOS ARQUIVOS *.PDF">
File diretorio = new File(inProcess);
File[] arquivos = diretorio.listFiles();
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="VERIFICAR SE HÁ ARQUIVOS NO DIRETÓRIO DESCRITO">
if (arquivos != null) {
//<editor-fold defaultstate="collapsed" desc="VERIFICAR TODOS OS ARQUIVOS NO DIRETÓRIO">
for (int x = 0; x < arquivos.length; x++) {
//<editor-fold defaultstate="collapsed" desc="ABRIR TODOS OS ARQUIVOS *.PDF DO DIRETÓRIO">
if (arquivos[x].getName().endsWith("pdf")) {
//<editor-fold defaultstate="collapsed" desc="ABRIR ARQUIVO *.PDF">
File f = arquivos[x];
try (RandomAccessBufferedFileInputStream acesso = new RandomAccessBufferedFileInputStream(f.getAbsolutePath())) {
PDFParser parser = new PDFParser(acesso);
parser.parse();
COSDocument cosDoc = parser.getDocument();
PDFTextStripper pdfStripper = new PDFTextStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="CRIAR ARQUIVO *.TXT">
FileWriter arq = new FileWriter(outPath + f.getName().replace(".pdf", ".txt")); //Diretório de saida
PrintWriter gravarArq = new PrintWriter(arq);
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="FECHAR BUFFER DO ARQUIVO *.TXT E DELETAR ARQUIVO *.PDF VERIFICADO">
arq.close();
acesso.close();
}
f.renameTo(new File(outPath, f.getName()));
//</editor-fold>
}
//</editor-fold>
}
//</editor-fold>
}
//</editor-fold>
} catch (IOException e) {
e.printStackTrace(); // Tratar a exceção adequadamente.
}
}
};
timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO); // Executa a tarefa
}
}
}
Add the code to the question. Without seeing it it gets a little complicated to deduce the reason for the problem.
– user28595
I just edited the question
– R.Santos
I ran the application in Netbeans and in the output it appears this message in red: java.io.Ioexception: Missing root Object Specification in trailer. at org.apache.pdfbox.pdfparser.Cosparser.parseTrailerValuesDynamically(Cosparser.java:2094) at org.apache.pdfbox.pdfparser.Pdfparser.initialParse(Pdfparser.java:201) at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:249)
 at Embratec.Embratec$1.run(Embratec.java:79)
 at java.util.Timerthread.mainLoop(Timer.java:555) at java.util.Timerthread.run(Timer.java:505).
– R.Santos
But the application is doing everything correctly
– R.Santos
Good afternoon, Read this post that will help you: http://answall.com/questions/28199/como-gerar-programa-execut%C3%A1vel-jar-no-netbeans
– Elvin
I discovered the error, I do not know why my application had not recognized any main method. I just added that and went on to perform perfectly
– R.Santos
It would be interesting to publish a reply with your solution and mark it as solved.
– Fagner Fonseca