Executables in a war file

这一生的挚爱 提交于 2019-12-23 09:47:34

问题


We'd like to ship some helper scripts (shell scripts) as part of an application war. Unfortunately it appears like our build system (maven) discard the permissions on all files and the scripts end up without the executable bit set.

Is it even possible to do that? Does the .war format support executable files? If yes: how could tell maven to keep the permissions/fix them somewhere in the process?


回答1:


The problem is more likely that these bits are not supported in the underlying zip-format.

The execute bit does not need to be set, if you explicitly execute /bin/sh with the script name.

Also note that your program - which knows the location of the script - can invoke "chmod +x script.sh" before launching.




回答2:


AFAIK, there is no way to set file permissions within a war/jar (this is however possible when using the Maven Assembly Plugin to create a binary distribution archive of your project, but this is another story).

So, I would either:

  • Deliver (as a binary distribution) and run these script outside the webapp ~or~
  • Read the files from the classpath, write them to the java.io.tmpdir directory, set the execution bit and then execute them from there ~or~
  • Use @Thorbjørn solution (didn't try that but I guess it would work); I'm just wondering from where you execute these scripts.



回答3:


You can also check and set the executable flag directly from your Java-Code. See http://docs.oracle.com/javase/6/docs/api/java/io/File.html#setExecutable%28boolean,%20boolean%29




回答4:


Supply the executables outside of the WAR. Call them from within the WAR.



来源:https://stackoverflow.com/questions/3188473/executables-in-a-war-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!