{"id":445,"date":"2007-11-17T13:20:40","date_gmt":"2007-11-17T19:20:40","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/archives\/000445"},"modified":"2007-11-17T15:11:13","modified_gmt":"2007-11-17T21:11:13","slug":"the-ant-jar-task-and-duplicate-files-can-cause-bizarre-behavior-and-missingincorrect-files-when-unzipping","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/445","title":{"rendered":"The ant jar task and duplicate files can cause bizarre behavior and missing\/incorrect files when unzipping"},"content":{"rendered":"<p>I just ran into some bizarre behavior.  I&#8217;m building a web application on Windows XPSP2, using Ant 1.6.1.  The application worked fine.  Then, I added one more copy instruction, to move a GWT component I&#8217;d just added to the appropriate place in the war file.  Suddenly, the application ceased to work.<\/p>\n<p>After a few hours of tracking down the issue, I found that it didn&#8217;t matter whether it was the new GWT component or an old one; it didn&#8217;t matter whether the copy went to the same directory or a new one&#8211;simply adding the new set of files caused the issue.  Then I noticed that the unzipped version of the application differed.  In particular, the configuration files differed.  That explained why the application wasn&#8217;t working&#8211;it wasn&#8217;t configured correctly.<\/p>\n<p>But, why were the configuration files different?<\/p>\n<p>I examined the generated jar file.  When I unjarred it, the configuration files were correct.  I was using the jar command, whereas the ant script was using unzip.  I made sure the jar file was copied correctly.  I made sure the old directory was deleted, and that the ant unzip task would overwrite existing files.  Still, no fix&#8211;I was seeing the incorrect configuration files.<\/p>\n<p>Then, this part of the jar task documentation jumped out at me:<\/p>\n<blockquote><p><a href=\"http:\/\/ant.apache.org\/manual\/CoreTasks\/jar.html\">Please note that the zip format allows multiple files of the same fully-qualified name to exist within a single archive. This has been documented as causing various problems for unsuspecting users. If you wish to avoid this behavior you must set the duplicate attribute to a value other than its default, &#8220;add&#8221;.<\/a><\/p><\/blockquote>\n<p>The other possible values for the duplicate attribute to the jar task listed are &#8220;fail&#8221; and &#8220;preserve&#8221;.  It doesn&#8217;t explain what the other options actually do; &#8220;fail&#8221; causes the jar task to fail when duplicate files are encountered.  This seems to be sane default behavior, and I&#8217;m not sure why it&#8217;s not the case.  &#8220;preserve&#8221; seems to preserve the first file added, and doesn&#8217;t add duplicates, but doesn&#8217;t tell you that duplicates exist.<\/p>\n<p><em>Update, 2:09:\u00a0\u00a0 &#8220;preserve&#8221; does tell you that duplicates exist, in this form: <code>WEB-INF\/web.xml already added, skipping<\/code><\/em><\/p>\n<p>I had, for a variety of reasons, a jar task that was adding two sets of the configuration files, with the same names and paths, to the war file.  Something about adding a few extra files seemed to flip a switch, and change existing behavior.  Whereas before, the unzip task picked the correct configuration file, now the unzip task picked the incorrect file.  I don&#8217;t know more than that, because I didn&#8217;t dig down into the source.<\/p>\n<p>The answer is to move the correct files to the top of the jar task, and change the &#8220;duplicate&#8221; attribute to be &#8220;preserve&#8221;.<\/p>\n<p>I hope this post saves someone a few hours of banging their head.<\/p>\n<p>[tags]ant, jar files, duplicate files, headbanging[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just ran into some bizarre behavior. I&#8217;m building a web application on Windows XPSP2, using Ant 1.6.1. The application worked fine. Then, I added one more copy instruction, to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-445","post","type-post","status-publish","format-standard","hentry","category-java","category-programming"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}