Rai*_*ung 5 java environment-variables maven
我可以在带有 的pom.xml-file 中使用当前用户名${user.name},但是有没有办法获取 uid (userid)?
我使用exec-maven-plugin并向执行添加参数。我尝试了不同的东西(${env.UID}, ${user.id}, $UID),但都不起作用。
我需要它在 docker 中启动一个将文件写入共享目录的进程。如果我不以-u-parameter开头,则所有文件都将属于root.
配置是这样的:
<configuration>
<executable>docker</executable>
<arguments>
<argument>run</argument>
<argument>-u</argument>
<argument>$UID</argument>
<argument>...</argument>
</arguments>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我打算编写一个 Maven 插件来提供该属性user.id,但后来我没有找到使用标准 java 方法获取 userid 的方法。
有两个项目(Java Native Access、Java Native Interface)可以直接访问本机信息,但到目前为止我还没有找到获取UID.
umask我通过在 Dockerfile 中添加 -call 解决了我的问题。我强烈建议使用不需要 maven 中的用户 ID 的解决方案。
但在解决这个问题时,我为真正需要这个的其他人创建了一个解决方案。user.name它从系统属性中获取-property,然后打开passwd-file 来搜索 uid。当然,这仅适用于类 UNIX 系统,并且它将构建直接与您的环境耦合,因此请明智地使用此解决方案(最好根本不使用)。
要使用我的解决方案,请将其添加到您的pom.xml:
<plugin>
<!-- Plugin only works with unix-like environments, please use it wisely! -->
<groupId>org.rjung.util</groupId>
<artifactId>user-id-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>user-id</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
873 次 |
| 最近记录: |