Hi I am writing a java application for linux(ubuntu) which has tray application and daemon application service.
I am able to execute the main application as daemon using yajsw, On User Login to the System I want the service to be notified which is have achieved (I have written script and placed in /etc/profile.d/
folder the script is getting executed from there I am connecting to the main application using TCP socket connection and pass the logged in user name)
Now from the main application I want to launch the Tray Application in the current logged in user desktop which will show the tray Icon ( SystemTray
of java.awt
) and popup menu. I have separate jar
file created for tray application.
One way to go is to launch the tray application in another process
Process p = Runtime.
getRuntime().
exec(new String[]{"bash","-c","java -jar /path/to/yourjar"});
Alternatively, you could just use the OS. Gnome, KDE and Unity all supports automatically starting applications at login. For example, on Gnome, scripts in ~/.config/autostart/
is automatically started when logging in.
Personally, I think the best way to go would be
Added the script file under /etc/X11/Xsession.d/98script which will be called on user login after session is created so that you can get the $DISPLAY value which is important for the java tray application to start in the session. From the script called the daemon java application which is listening on the tcp port From the daemon java application execute the startapp script pass the logged in username and his DISPLAY in startapp script export DISPLAY and export USERNAME and execute the tray application which will launch in user session and tray is displayed in the same display area
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.