Java Runtime execution not working in cron job @reboot showing error "Unable to connect to X server"

I have a bash script to be executed using a jar file, Im using the Runtime method as given below:

`Process proc = Runtime.getRuntime().exec("bash /location/to/bash.sh");`

The script executes well when the jar file is run from the terminal but when It comes to cron (sudo) it’s not executing the Script.

I tried logging the process.ErrorStream(); and got an error “unable to connect to X server”.

I tried using ProcessBuilder in java but it’s still not working.

I tried How to Autorun Application at the Start up in Linux (toradex.com)
section GRAPHICS, but It’s not coming out from the # wait for weston loop.
I’m a newbie… can someone help to come out from this issue?

Hi @rickoonidioser

Welcome to Toradex community.

Could you provide the hardware and software versions of your setup?
Are you able to solve the issue? if not could you attach the steps to reproduce the issue at our end.