I need to permanently modify the system's PATH
environment variable. For this I'm planning to check if the folder I'm about to add already exists and only if it doesn't, it gets added.
String pathToAdd = "C:\\Example\\bin";
String pathContents = getPathSystemEnvironmentValue();
if(!pathContents.contains(pathToAdd))
{
pathContents += ";" + pathToAdd;
}
setPathSystemEnvironmentValue(pathContents);
Unfortunately, I don't know how to retrieve and set the PATH
environment variable conveniently. I've seen that it can be done by using the setx command but it would not use any Java code and it's obviously not platform-independent. I also want to avoid calling external batch files. I know that Java wasn't meant to do native tasks like this but is there a decent solution though? Possibly compatible with Linux
as well.