I have written a Java application which is now compiled into a jar. Inside the applications main method I want to have the following:
Runtime.exec("java -jar myapp.jar arg1 arg2"))
(Or with Processbuilder if it's better)
I.e. the application should fork itself and create new processes.
So far, so good... my problem is now that I think that I cannot just call "java" but I have to give the full path to the java directory and I also think that I have to give the full path to myapp.jar.
Is there a way to avoid hardcoding the full path? I.e. that the java path and the path to myapp.jar is inferred at runtime inside the Runtime.exec?
Moreover, is it possible that the application can infer its name at runtime? I.e. the applications name is myapp.jar but I don't want to hardcode it in the Runtime.exec(...).
Edit: I need it on Ubuntu but also running in Windows.