I have a textfile x.txt on a server: SunOS aserver 5.9 Generic_112233-08 sun4us sparc FJSV,GPUS I use gzip 1.3 (1999-12-21) to zip it. The file becomes x.txt.gz Through FTP I download the file binary to my PC (Win 2000 Professional). I run in a task only the following: <unzip src="c:\jtemp\zipped\x.txt.gz" dest="c:\jtemp\unzipped"/> When running only this task, I get: C:\dvl.home\prj\ksz\build.xml:223: Error while expanding C:\jtemp\zipped\x.txt.gz at org.apache.tools.ant.taskdefs.Expand.expandFile(Expand.java:169) at org.apache.tools.ant.taskdefs.Expand.execute(Expand.java:133) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:302) at org.apache.tools.ant.Task.perform(Task.java:401) at org.apache.tools.ant.Target.execute(Target.java:338) at org.apache.tools.ant.Target.performTasks(Target.java:365) at org.apache.tools.ant.Project.executeTarget(Project.java:1237) at org.apache.tools.ant.Project.executeTargets(Project.java:1094) at org.apache.tools.ant.Main.runBuild(Main.java:669) at org.apache.tools.ant.Main.startAnt(Main.java:220) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90) --- Nested Exception --- java.io.IOException: Negative seek offset at java.io.RandomAccessFile.seek(Native Method) at org.apache.tools.zip.ZipFile.positionAtCentralDirectory (ZipFile.java:396) at org.apache.tools.zip.ZipFile.populateFromCentralDirectory (ZipFile.java:274) at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:180) at org.apache.tools.ant.taskdefs.Expand.expandFile(Expand.java:158) at org.apache.tools.ant.taskdefs.Expand.execute(Expand.java:133) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:302) at org.apache.tools.ant.Task.perform(Task.java:401) at org.apache.tools.ant.Target.execute(Target.java:338) at org.apache.tools.ant.Target.performTasks(Target.java:365) at org.apache.tools.ant.Project.executeTarget(Project.java:1237) at org.apache.tools.ant.Project.executeTargets(Project.java:1094) at org.apache.tools.ant.Main.runBuild(Main.java:669) at org.apache.tools.ant.Main.startAnt(Main.java:220) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:215) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:90)
The task gunzip works well in this case but I my situation I can't use gunzip because I want to use filesets: all the .gz-files in my directory have to be uncompressed.
This is not a bug. You are using the incorrect uncompression method. You need to use <gunzip> instead of <unzip>. <unzip> will think that this is a zip file and not a gzip file.
Ikkk. You are right, the guzip task does not take a fileset ! And one cannot set the compression method for unzip or use the untar task.
As a work-around (and when ant 1.6 beta3 comes out soon..) you can use <for> from ant-contrib, (for is like foreach but it uses macrodef instead of antcall so it is currently faster for each iteration). <project default="u" xmlns:ac="antlib:net.sf.antcontrib"> <target name="u"> <mkdir dir="unzipped"/> <ac:for param="file"> <ac:path> <ac:fileset dir="${basedir}" includes="**/*.gz"/> </ac:path> <ac:sequential> <gunzip src="@{file}" dest="unzipped"/> </ac:sequential> </ac:for> </target> </project>
Thanks for the quick answer. Quicker than the helpdesk of some paying software ;-) But what do I have to install to make it work ? I read and tried different things but it doesn't work. Probably I don't have enough knowledge of ant-contrib. But probably I am not alone and is it usefull to share it to others through these bug-comments...
First for the <for> task, you need ant 1.6 beta3, just released. Then you need a cvs version of ant-contrib, or take the lastest gump compiled jar at http://gump.covalent.net/jars/latest/ant-contrib. Place the ant-contrib.jar into the $ANT_HOME/lib directory. You can then use the antlib namespace shortcut: <project xmlns:ac="antlib:net.sf.antcontrib"> <ac:for ...> </project> or use a <taskdef resource="net/sf/antcontrib/antcontrib.properties"> or <typedef resource="net/sf/antcontrib/antlib.xml"/> to access the tasks without using namespaces.
Hoera, it works ! Thanks a lot !!!