JAR converted to exe does not open after being transferred via socket

Asked

Viewed 40 times

1

I have a JAR program that I converted to EXE with Launch4j. The EXE works normal, but when I try to transfer this file via socket it just doesn’t open with 2 clicks.

If I use a "java -jar.exe file" it opens normal. Just do not open by double clicking on it. Does anyone have any idea what it might be?

I don’t think it’s a transfer problem, but here are the classes that do it.

Client:

private void receiveVersion(String version) {
    DataOutputStream out = null;
    InputStream ins = null;
    DataInputStream dis = null;
    BufferedOutputStream bos = null;
    Socket client = null;
    try {
        String host = (Constants.SERVER_HOST.contains("localhost") ? "localhost" : Constants.SERVER_HOST);
        client = new Socket(host, 9780);
        //Abre os devidos canais de comuicação
        out = new DataOutputStream(client.getOutputStream());
        ins = client.getInputStream();
        dis = new DataInputStream(ins);
        //Envia a versao para realizar o download
        out.writeUTF(version);
        //Recebe o tamanho do arquivo
        long tamanho = dis.readLong();
        //FileOutputStream para salvar o arquivo
        File path = new File(".");
        File original = new File(path, "MEUJAR.exe");
        if (original.exists()) {
            original.delete();
            original = null;
        }
        System.out.println("<<< VersionUpdaterClient - ARQUIVO SENDO CRIADO EM " + path.getAbsolutePath() + " >>>");
        File finalFile = new File(path, "MEUJAR.exe");

        bos = new BufferedOutputStream(new FileOutputStream(finalFile));
        //Recebe os bytes do server
        byte[] buffer = new byte[16384];
        //Envia os bytes
        Integer leitura = null;
        Integer count = 0;
        do{
            leitura = ins.read(buffer, 0 , buffer.length);
            count += leitura;
            bos.write(buffer, 0, leitura);
            bos.flush();
        } while(leitura != -1 && count < tamanho);
        bos.close();
        System.out.println("<<< VersionUpdaterClient - ARQUIVO CRIADO COM SUCESSO " + finalFile + " " + finalFile.length() + " >>>");
        //Desktop.getDesktop().open( new File( "MEUJAR.exe" ));  ====> Também não funciona
        new ProcessBuilder("java", "-jar", "MEUJAR.exe").start(); // Assim funciona
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (client != null) {
                client.close();
            }
            if (ins != null) {
                ins.close();
            }
            if (out != null) {
                out.close();
            }
            if (dis != null) {
                dis.close();
            }
            if (bos != null) {
                bos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}

Server:

private void sendVersion(Socket client) {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            OutputStream os = null;
            DataOutputStream dos = null;
            DataInputStream dis;
            BufferedInputStream bis = null;
            try {
                dis = new DataInputStream(client.getInputStream());
                os = client.getOutputStream();
                dos = new DataOutputStream(os);
                String actualVersion = dis.readUTF();
                System.out.println("<<< VersionUpdaterService - INICIADO ENVIO DE VERSAO "+actualVersion+" PARA " + client.getInetAddress());
                File file = new File(VERSIONS_PATH + actualVersion + "\\MEUJAR.exe");
                bis = new BufferedInputStream(new FileInputStream(file));

                //Envia o tamanho do arquivo
                dos.writeLong(file.length());
                dos.flush();

                //Cria um buffer
                byte[] buffer = new byte[16384];
                //Envia dados
                Integer leitura = null;
                do {
                    leitura = bis.read(buffer, 0, buffer.length);
                    System.out.flush();
                    if (leitura != -1) {
                        os.write(buffer, 0, leitura);
                    }
                    os.flush();
                } while (leitura != -1);
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (os != null) {
                        os.close();
                    }
                    if (dos != null) {
                        dos.close();
                    }
                    if (client != null) {
                        client.close();
                    }
                    if (bis != null) {
                        bis.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    t.start();
}
  • Running only arquivo.exe he opens?

  • Open yes. Only stops opening when I transfer it.

  • When you say transfer via socket, is it to a different computer? Or is it to the same computer from which it was sent? How it opens using the command line is probably error in setting the path to jre when creating the executable (provided it works on the same computer).

  • I’m testing for the same computer. And I discovered something weirder... That transferred file that doesn’t open with double click only doesn’t work if I leave it on the Desktop. If I play it in a folder, it opens with 2 clicks... You’ll understand.

No answers

Browser other questions tagged

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