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

1

I have a JAR program that I converted to EXE with Launch4J. The EXE works fine, but when I try to transfer this file via socket it just does not open with 2 clicks.

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

I do not think it's a problem in the transfer, but here are the classes that perform 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();
}
    
asked by anonymous 23.12.2017 / 20:28

0 answers