0

I'm currently developing a cross-platform application (Windows, Mac OS X, Linux) with Java and building the project on Windows. During the build process, I construct a shell-script for Linux to "wrap" the executable jar-file.

I set the executable bit of the shell script as follows:

File script = new File("run.sh");
script.setExecutable(true);

But when transferring the run.sh file to Linux, I always end up with the following permissions:

-rw-r--r-- 1 salocinx salocinx 120 2014-08-20 20:21 run.sh

Anybody knows how to preserve the x-bit from Windows to Linux ?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
salocinx
  • 3,715
  • 8
  • 61
  • 110

2 Answers2

2

Your file transfer program would need a preserve permissions option. I don't think you're going to find one. You could run your program on the unix box to change the file permissions, or you could run a find command like

find . -name "*.sh" -exec chmod a+x {} \;

Or you could try setting your umask,

umask u+x

Or (if you're using cygwin), you could use tar with

tar cfp file.tar <scripts>

note that p is preserve permissions.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Okay I'll simply build the project on Linux and then pack the entire project into a *.tar.gz file in order to distribute it onto other Linux- and Mac-based machines. Thanks for the hints! – salocinx Aug 20 '14 at 18:48
1

setExecutable doesn't do anything on Windows, it returns false if it fails, you can check.

Windows filesystems have no concept of executable permission.

What permissions files have after transferring to Linux, depends on the program you used to transfer them, but usually they'll be 600 or 644. To solve this, you have to set the executable bit under a Unix-like operating system on a suitable filesystem.

Karol S
  • 9,028
  • 2
  • 32
  • 45