Create a executable from a Java application

Asked

Viewed 368 times

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.

  • I just edited the question

  • 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)&#xA; at Embratec.Embratec$1.run(Embratec.java:79)&#xA; at java.util.Timerthread.mainLoop(Timer.java:555) at java.util.Timerthread.run(Timer.java:505).

  • But the application is doing everything correctly

  • Good afternoon, Read this post that will help you: http://answall.com/questions/28199/como-gerar-programa-execut%C3%A1vel-jar-no-netbeans

  • 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

  • It would be interesting to publish a reply with your solution and mark it as solved.

Show 2 more comments

1 answer

1


I had to go in the properties of my project because it was without any given main class, follows image of the place where the information changes.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.