javaadminsudojavapackager

How to enforce packaged java app to run as admin


I'm trying to package a java application using java packager tool ( I'm new to this tool ) the app itself has to make some calls internally ( using the java process api )

This works fine if the java application is started with admin privileges. for example if I run my jar app as sudo java -jar application.jar from then all sub processes become admin as well.

For distribution purpose , I do not have control over how the users will start the app. thus trying to use java packager tool- but I need to enforce that the app is ran with admin privileges. ( fine the app will stop if the user does not have sudo for example )

The other workaround , which I strongly want to avoid is to ask the user to enter their admin/sudo password when I launch the internal processes..

---EDIT--- I think I needed to add more background after the comments and answer I got. as it looks to though the issue is about detecting admin or not.. this is not not what my issue is.

class MyApp...
main(...){
   System.exec("start format.app")
}

format.app requires admin to work.

I use javapackager tool to distribute MyApp.app ( for mac ) MyApp.exe ( for windows ) etc ...


Solution

  • SOLVED by adding preinstall script to the javapackager. the script will run as root at deploy time giving me control of prepraing anything the app needs at runtime.