Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On my end if I build your project using the <code>pom.xml</code> you've showed us, with <code>apache-poi</code> declared after <code>jfreechart</code>, then as you've mentioned I get a corrupt JAR. Swapping the order of these two dependencies indeed gives me a correct JAR.</p> <p>I've some previous experience with the <code>maven-shade-plugin</code> and when I used it I had trouble with the created JAR's <code>META-INF</code> directory, so I've checked that for defects.</p> <p>I've tried to copy (using Total Commander) the <code>META-INF</code> directory somewhere on my local filesystem and what I've noticed is that there were errors while copying the files in <code>META-INF/licences/</code>. If I've tried to copy those somewhere individually and it worked but I couldn't copy the whole thing. My conclusion was that the JAR/ZIP archive is corrupt.</p> <p>What I did was I <em>entered</em> that JAR in Total Commander (<kbd>Ctrl</kbd>+<kbd>PgDown</kbd> <em>over</em> the JAR file) and I <em>renamed</em> <code>thirdpartylicenses.txt</code> to <code>thirdpartylicenses.txt.wtf</code>. Doing this Total Commander offers to save this and it repackages the JAR (I've the Total7zip Total Commander packer plugin installed - if anyone tries this and it doesn't work try it with this installed).</p> <p>After this. It works.</p> <p>(I've also tried to repack the whole thing without renaming anything using Cygwin's <code>unzip</code>/<code>zip</code> commands, but that didn't work the new archive was still corrupt. Total Commander or the plugin I've mentioned does some magic.)</p> <p>I guess the <code>maven-shade-plugin</code> merely creates a corrupt or invalid ZIP/JAR archive. I'm not sure why and maybe what I've described won't work for anyone else but I thought I'd mention it so maybe I could help.</p> <hr> <p>I couldn't just leave this alone, so I've dug deeper and I think I've found the answer.</p> <p>The <em>bad</em> JAR contains 65608 entries. The <em>good</em> JAR contains 65450 entries.</p> <p>Guess what's the upper limit of <a href="http://en.wikipedia.org/wiki/ZIP_%28file_format%29#ZIP64" rel="nofollow noreferrer">the number of entries for a <em>plain</em> ZIP file</a>? Yeah. The Wiki article speaks about a ZIP64 format which overcomes this limitation.</p> <p>The <em>good</em> JAR has less entries because the actual dependencies change because of the position of the dependency declarations in your <code>pom.xml</code>. (<a href="https://stackoverflow.com/a/13088093/433835">As described by this answer.</a>)</p> <p>I've counted the entries like this.</p> <pre><code>Collections.list(new JarFile("...").entries()).size(); </code></pre> <p>I was using <a href="https://stackoverflow.com/a/9616474/433835">Java 7 which seems to support the new ZIP64 format</a>, so maybe if someone tries to count the entries in the <em>bad</em> JAR using Java 5 or 6 will receive an error (I'm not sure though).</p> <p>I also tried to run the JAR <em>exploded</em>. I've unpacked the whole JAR into a directory and run the whole thing like this.</p> <pre><code>java -cp &lt;dir/ com.mycompany.test.Start </code></pre> <p>Worked like a charm.</p> <hr> <p>Bottom line. Don't <em>overuse</em> the <code>maven-shade-plugin</code>.</p> <p>I have a project at work where I build my project like this.</p> <ul> <li>I copy my project's dependencies using the <a href="http://maven.apache.org/plugins/maven-dependency-plugin/" rel="nofollow noreferrer"><code>maven-dependency-plugin</code></a>. Checkout the <a href="http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html" rel="nofollow noreferrer"><code>copy-dependencies</code> goal</a>. This copies your dependencies into <code>target/dependency</code> if I remember correctly.</li> <li><p>Using the <a href="http://maven.apache.org/plugins/maven-jar-plugin/" rel="nofollow noreferrer"><code>maven-jar-plugin</code></a> I add these dependencies to my final JAR's <code>MANIFEST.MF</code> as <code>Class-Path</code> entries using these options in the plugins configuration.</p> <pre><code>&lt;classpathPrefix&gt;dependency/&lt;/classpathPrefix&gt; &lt;addClasspath&gt;true&lt;/addClasspath&gt; </code></pre> <p>So I'll have <code>Class-Path</code> entries like <code>dependency/&lt;artifactId&gt;-&lt;version&gt;.jar</code>, etc.</p></li> <li>After this I'm using the <a href="https://maven.apache.org/plugins/maven-assembly-plugin7" rel="nofollow noreferrer"><code>maven-assembly-plugin</code></a> to create a distribution ZIP which contains my final JAR and the whole <code>dependency/</code> folder.</li> <li>When I deploy my application I can run it like <code>java -jar final.jar</code>.</li> </ul> <p>Primarily I've opted to use this solution, because in my project I use some Bouncy Castle JARs which JARs have some extravagant <em>this and that</em> inside their <code>META-INF</code> directory. When I used the <code>maven-shade-plugin</code> to create my final runnable JAR all hell broke loose and I got nasty <em>that method couldn't be found and this signature is not quite right</em> errors.</p> <p>You should be doing something like this also. This Maven shade business is too <em>shady</em> to be useful (pun intended).</p> <hr> <p>Here's <a href="http://ath3nd.wordpress.com/2013/12/25/packaging-a-multimodule-maven-spring-app-in-a-standalone-jar/" rel="nofollow noreferrer">a blog post on the whole process that I've tried to describe</a> just above (thanks to <a href="https://stackoverflow.com/users/487649/baba">baba</a>), maybe it'll help someone in the future.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload