7

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?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
reto
  • 16,189
  • 7
  • 53
  • 67
  • May I just ask how these helper scripts are going to be used (and by who)? – Pascal Thivent Jul 06 '10 at 17:05
  • by the application itself :), I know, this is not the 'JE22' way, but we have to transfer some result files to different hosts using scp and ftp. Doing this with a simple shell script (which gets the result file as an argument) is a no-brainer. we dont want to do this with plain-java. – reto Jul 06 '10 at 17:10

4 Answers4

5

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • I had realized this and done it in another project, but still came here looking for the solution , just to remember what I did earlier. :) – Ashishkel Aug 07 '20 at 19:42
1

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

Clemens82
  • 186
  • 1
  • 3
1

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.
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
0

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

mcandre
  • 22,868
  • 20
  • 88
  • 147
  • That's a solution but it brings other problems (maintenance is the first one to come to my mind). I'm not sure it should be a best practice. – Mick F Oct 31 '11 at 17:23
  • Alternate solution: Supply the executable inside the WAR, and at every run, programmatically extract the executable to the same directory and call it there. – mcandre Oct 31 '11 at 19:43
  • I've tried this solution but couldn't make it work. For some reason, the class loader couldn't find my script resource. I'll spend another hour or so working on it, and if it fails, it will be an opportunity for a new question :) – Mick F Nov 01 '11 at 18:19
  • @DirtyHenry I think you should post that as a separate question, since that basic functionality isn't working for you. It's hard to resolve this question until you know that answer. – mcandre Nov 01 '11 at 20:40
  • 1
    Done: http://stackoverflow.com/questions/7974837/how-can-i-locate-a-non-java-resource-in-a-war-at-runtime :) – Mick F Nov 02 '11 at 01:26