fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.07k stars 133 forks source link

After packaging JavaFX into deb, there was no response or error when executing the gsetting command after installation and running #440

Closed fubb-github closed 4 weeks ago

fubb-github commented 4 weeks ago

In Ubuntu system, this is a piece of code included in the program that is used to open the system agent. It successfully opens the system agent during the development and running of Idea, and can also be successfully opened by opening the terminal and executing the command separately. Executing the jar package can also successfully open the system agent. However, after packaging and installing, the system agent is not opened, and no error stream or exception is output. Why is this? Logging in to the desktop operating system as the root user can also be successful, while other users may not be successful even if they have administrator privileges;

private boolean executeCommandSingleLine() {
String command = "gsettings set org.gnome.system.proxy mode 'auto' && gsettings set org.gnome.system.proxy autoconfig-url 'http://127.0.0.1:18080/pac'";
        Process process = null;
        BufferedReader reader = null;
        AtomicBoolean result = new AtomicBoolean(true);

        try {
            process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", command});
            System.out.println("process info  ---> " + process.info().toString());
            BufferedReader errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            String line1;
            while ((line1 = errReader.readLine()) != null) {
                System.out.println(line1);
            }
            System.out.println("--------------------------------");
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            System.err.println("Error executing command: " + e.getMessage());
            result.set(false);
        } finally {
            if (process != null) {
                process.destroy();
            }
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    // Ignore
                }
            }
        }

        return result.get();
    }
fvarrui commented 4 weeks ago

Hi @fubb-github! I guess you've managed to fix this issue. Was it related to JavPackager?