Universal Robots Forum

Java daemon will not start

Iv’e created a java daemon and added to the MyDaemon example. It will run fine when launched manually outside the URCap project however, it does not want to start when path added to the getExecutable() function. Anything special that needs to be done here to get it to start()?

   @Override
	public URL getExecutable() {
		try {
			return new URL("file:com/ur/urcap/examples/mydaemon/impl/daemon/MyDaemonJavaServer-0.1.jar"); // Java
		} catch (MalformedURLException e) {
			return null;
		}
	}
1 Like

Hello @rculhane,

What version of the sdk are you using? Take a look at this thread there was a similar problem that was addressed recently: Daemon service does not start any longer

1 Like

Thank you for the suggestion. I was using an older API but changed to 1.5.0. Still not working though on simulator polyscope “5.2” or my real robot polyscope “3.8”.

There are some other suggestions in that thread I haven’t tried yet.

1 Like

OK figured this out mostly. Yes, it was a simulator (or Linux) issue causing most of my headaches. Can’t start any Daemon in the simulator now. Once I got past that realization I found a way to start the java daemon just testing on the robot.

Solution:
Add a shell file to the same folder as the Java Daemon “RunMDJS.sh”.
#!/bin/bash
echo “Start MyJavaDaemonServer.jar”
java -jar MyJavaDaemonServer.jar

In the MyDaemonDaemonService.java file getExecutable:
return new URL("file:com/ur/urcap/examples/mydaemon/impl/daemon/RunMDJS.sh"); // Java

However, stopping the Daemon is another issue. I would appreciate other suggestions to help make this fully functional.

2 Likes

I’m having exactly the same issue. I just didn’t have the time to address it jet, as manually it works well. So it’s in still in my ToDo list. I’ll try your solution and let you now if it works for me too.
And by the way, recently I had the chance to test this on a CB3.0 and it works! So the problem with MyDaemon example not being able to successfully start the daemon occurs with CB3.1 (I tested it with 3.6.1 and 3.8 fresh images on real robot, and with the SDK 1.3.55 simulator SW 3.6.0.30512 and doesn’t work). Still no chance to test it on e-Series, so I don’t know about it.

1 Like

So I had the same issue and found a way to stop the daemon. I worked around it by having the bash script kill the daemon jar on exit.

Here is my code, the jar file was named daemon.jar:

#!/bin/bash
function cleanup {
echo “killing”
jarid=$(pgrep -f “daemon.jar”)
kill $jarid
}
echo “daemon on”
trap cleanup EXIT
java -jar daemon.jar

1 Like