I'm fairly new to the world of java and the Pi so please bear with me and explain to me in great detail how to fix my problem.
So as the title says, I'm trying to run a Swing GUI at start up and have managed to get it to partially work. I used the file /etc/rc.local
to run a quick execution
export DISPLAY=0.0
sudo java -jar /home/pi/NetBeansProjects/FanController/dist/FanCOntroller.jar
NOTE: Wont run without the export DISPLAY=0.0 part.
On initial operation everything looked great but when I started to play with the program I noticed that it was acting strangely when I changed a few values. Basically the program allows a user to set a temperature for turning a fan on and set another setting for turning the fan back off.
What I noticed is that when I set the value to less than the current temperature it started to switch the output on and off rapidly as if there was something conflicting with it. From further investigation I can only assume that there are 2 instances of the program running. One on the touch screen display I have plugged in and the other in the background somewhere.
I have VNC on the Pi so maybe even when I'm not connected to it, there's still a hidden version of it running as when I do start the VNC connection I get the same issue. If I update the settings on the touch screen, it doesn't automatically update on the VNC connection and visa versa.
Is there a way of ensuring only one instance of the program is running or is there a better way of auto starting the application. I've tried many different approaches but none work.
1. Create a file named /etc/xdg/autostart/startup.desktop
2. Put the following contents into it
[Desktop Entry] Type=Application
Name=JavaApplication
Exec=/user/home/jre/java -jar javafile.jar
3. Restart.
Attempted to add it to the following file
/etc/edg/lxsession/LXDE-pi
With no luck
Attempted this
sudo update-rc.d {path of the script}/FanController.sh defaults
Created a .sh file with the command to start the program and again wouldn't start.
Any help would be great please.
UPDATE:
Got this sorted. The issues was as I suspected, I was running 2 instances of the same program and they where fighting against each other. To this end I stopped using tightVNC and started using x11vnc. x11vnc doesn't start up a second instance of the desktop. It allows me to view the actual output of the display adapter. Downside is that the remote connection was a small window but i'll live with it.
Thanks again for all the suggestions.