How to 'Chmod -R +W' with Ant, Files and Folders

How to `chmod -R +w` with Ant, files and folders?

The following does work:

<chmod file="${basedir}/foo/**" perm="g+w" type="both"/>

Credits shared with the OP.

See also

  • Chmod Task

Remotely change permissions of a UNIX file using chmod ant task within WebSphere MQ FTE?

To do this as a WMQ FTE task you would use a Managed Call if the entire task was to change the permissions, or you would use a pre- or post-transfer call if you needed to change the permissions either before or after the transfer.

The call or task could directly execute chmod but that would require the sandbox to include a directory containing many potentially dangerous commands. It would be better to make a script that invoked chmod or a link to chmod and put the script or link in a dedicated bin directory sandboxed for the FTE agent.

How do I programmatically change file permissions?

Full control over file attributes is available in Java 7, as part of the "new" New IO facility (NIO.2). For example, POSIX permissions can be set on an existing file with setPosixFilePermissions(), or atomically at file creation with methods like createFile() or newByteChannel().

You can create a set of permissions using EnumSet.of(), but the helper method PosixFilePermissions.fromString() will uses a conventional format that will be more readable to many developers. For APIs that accept a FileAttribute, you can wrap the set of permissions with with PosixFilePermissions.asFileAttribute().

Set<PosixFilePermission> ownerWritable = PosixFilePermissions.fromString("rw-r--r--");
FileAttribute<?> permissions = PosixFilePermissions.asFileAttribute(ownerWritable);
Files.createFile(path, permissions);

In earlier versions of Java, using native code of your own, or exec-ing command-line utilities are common approaches.

Keep permissions on files with Maven resources:testResources

This seems to be a bug in the Maven Resource Plugin

If you are using the Maven Assembly Plugin, you can configure the file permissions there.

If not, you might consider a workaround. You could do this via Ant by doing something like this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>process-test-classes</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod file="target/test-classes/test.sh" perm="755"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

How to grant Tomcat 9 access on other files

Add the tomcat to a group and grant this group the required access to that files, i.g. you can create a group called webserver. Then restart tomcat and try again.


Steps

$ sudo groupadd webserver
$ sudo usermod -a -G webserver tomcat9
$ sudo chgrp webserver configuration.yaml
$ sudo chmod g=rw configuration.yaml
$ sudo systemctl restart tomcat9

, Update the group ownership of the directories (that contains the files) by adding the permissions to it

$ sudo chgrp webserver /opt/zigbee2mqtt/data/
$ sudo chgrp webserver /opt/zigbee2mqtt/
$ sudo chmod g=rwx /opt/zigbee2mqtt/data/
$ sudo chmod g=rwx /opt/zigbee2mqtt/


Related Topics



Leave a reply



Submit