Rainer Jung Rainer Jung - 11 months ago 101
Java Question

Get UID in a maven variable?

I can the the current username in a

-file with
, but is there a way to get the uid (userid)?

I use
and add arguments to a execution. I've tried different things (
), but neither work.

I need it to start a process in docker that writes files to a shared directory. If I don't start with the
-parameter all files will belong to

The configuration is like:


Answer Source

I intended to write a maven plugin to provide the property user.id but then I did not find a way to get the userid with standard java methods.
There are two projects (Java Native Access, Java Native Interface) to have direct access to native informations, but so far I haven't found a way to get the UID.

I fixed my problem by adding a umask-call in my Dockerfile. I strongly recomend to use a solution that does not requires the user-id within maven.

But working on the issue I created a solution for others that really need this. It takes the user.name-property from the system-properties and then opens the passwd-file to search for the uid. Of course this will only work for unix-like systems and it couples the build directly with your environment, so use this solution wisely (idealy not at all).
To use my solution, add this to your pom.xml:

  <!-- Plugin only works with unix-like environments, please use it wisely! -->