Wednesday, January 9, 2008

In-file property expansion in Eclipse

This defect in Eclipse and Rational Application Developer is driving me nuts at the moment..

https://bugs.eclipse.org/bugs/show_bug.cgi?id=206362


However, according to my good friend Google, Netbeans also struggles with In-file property expansion.

ANT and file permissions

When using the JAR or WAR tasks in ANT, permissions are not inherited in a non-Windows environment. This is due to security issues in the JVM. Instead, the permissions are set to 0644 by default.

There are a few ways to get around this.

When using the JAR task, use the chmod task directly afterwards to set the permissions. The chmod task does does not work correctly in Windows, but will work correctly in UNIX.. go figure.

<!-- Jars all class files in parent directory and then sets the jar file to rwxr-xr-x permissions -->
<jar destfile="myjar.jar">
   <fileset dir="./" includes="**/*.class" />
</jar>

<chmod file="myjar.jar" perm="755">



When using the WAR task, the same is true. However, I am using a zipfileset below, which extends the fileset element, but allows the user to set permissions on the files within the fileset. In this case, I had to set all jars to 755 in order for them to be executable for an applet. First, I had to exclude all jars from the war element. Next, include them in the zipfileset, setting the filemode, or file permissions, to 755, or rwxr-xr-x. Example:

<war destfile="mywar.war" manifest="manifest.mf" basedir="./" excludes="**/*.jar">
   <zipfileset dir="." includes="**/*.jar" filemod="755"/>
</war>


One more thing to note: I've read in other blogs that the chmod element tends to work erratically in Windows due to security flaws. You may want to envelope the chmod in an ant target that depends on the OS like in the example below:

<!-- Calls chmod if the OS is NOT a Windows Operating System -->
<condition value="isWindows">
   <os family="windows"/>
</condition>

<target name="chmodFile" unless="isWindows">
   <chmod file="myjar.jar" perm="755" />
</target>

<antcall target="chmodFile" />