A java library to run pieces of code as root using native root password input dialog.
A new JVM is created in every execution and destroyed after completion.
This library uses Out Process to create new JVMs.
- Ask user for credentials in Windows, Linux and macOS.
- Do privileged actions.
- Limit scope of root code execution.
- Upgrade permissions during runtime temporarily.
// Specify JVM options (optional)
RootExecutor rootExecutor = new RootExecutor("-Xmx64m");
// Execute privileged action without return
rootExecutor.run(() -> {
// Call your admin code here.
}));
// Execute privileged action with return
Object value = rootExecutor.call(() -> {
// Call your admin code with return here.
return null;
}));
System.out.println(value);
- Init simple, after include this lib in your project just try to write a file in a protected folder to validate if it is working.
- Avoid big classpaths, it can be a problem in Windows. #8
<dependency>
<groupId>com.github.dyorgio.runtime</groupId>
<artifactId>run-as-root</artifactId>
<version>1.2.3</version>
</dependency>