Ant build.xml requires user input, but Eclipse has

2019-02-27 03:17发布

I'm trying to better integrate Eclipse with my build.xml. My build file calls GNU Make for the native portion of the program, and the Makefile uses sudo to movethe compiled libs into system path. Unfortunately that requires entering a password, and Eclipse's terminal doesn't accept user input. So the result from running the build in eclipse is:

 [exec] sudo: no tty present and no askpass program specified
 [exec] make: *** [install] Error 1

Any way around this problem? Can the ant build be elevated to root some other way?

3条回答
家丑人穷心不美
2楼-- · 2019-02-27 04:05

Set up a separate account, e.g. deployer. Modify /etc/sudoers to include aliases that allow deployer to execute a single command, e.g. deploy, as root. Make deployer NOEXEC:. Store the deployer password in an invisible file, e.g. .deployconf having user-only access: e.g. 400 or 600. Load the password in ant, and use as required:

<loadfile srcfile="${user.home}/.deployconf" property="deployconf"/>

This works well with <signjar/>, but I've not tried it with <exec/>. Some effort may be required to keep linefeeds out of .deployconf.

查看更多
祖国的老花朵
3楼-- · 2019-02-27 04:06

You could set up your /etc/sudoers file so that it specifies NOPASSWD: for the user under which Eclipse is running, and for the command you're using to move the libs. Using the visudo command, you could add this to the end of /etc/sudoers:

eclipseuser ALL = NOPASSWD: /bin/cp

Be aware that this does present a security risk as the eclipseuser would then have the power to overwrite any file on the system.

查看更多
Root(大扎)
4楼-- · 2019-02-27 04:10

Perhaps a stupid 'solution', but why not make the deploy a separate step? Have the build make an packaging artifact: DEP, RPM or something.

查看更多
登录 后发表回答