title: Hello World Ear: NoModuleFileException: A file does not exist for module element having uri: core-api.jar
body: <p>I have what is a simple EAR file configured like so:</p>
  
  <pre><code>app.ear
  |-- lib/...
  |-- META-INF/application.xml
  |-- core.jar
  |   |-- test/MyServiceImpl.class
  |   `-- META-INF/MANIFEST.MF // Class-Path: core-api.jar 
  |-- core-api.jar
  |   `-- test/MyService.class
  `-- web.war
      `-- META-INF/MANIFEST.MF // Class-Path: core.jar core-api.jar
  </code></pre>
  
  <p>The application.xml is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;application xmlns="http://java.sun.com/xml/ns/javaee" id="app 1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6"&gt;
    &lt;application-name&gt;MyApp&lt;/application-name&gt;
    &lt;display-name&gt;My App&lt;/display-name&gt;
    &lt;module id="mod 1"&gt;
      &lt;java&gt;core-api.jar&lt;/java&gt;
    &lt;/module&gt;
    &lt;module id="mod 2"&gt;
      &lt;java&gt;core.jar&lt;/java&gt;
    &lt;/module&gt;
    &lt;module id="mod 3"&gt;
      &lt;web&gt;
        &lt;web-uri&gt;web.war&lt;/web-uri&gt;
        &lt;context-root&gt;/&lt;/context-root&gt;
      &lt;/web&gt;
    &lt;/module&gt;
    &lt;library-directory&gt;lib&lt;/library-directory&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>When i attempt to deploy the application to the server, I get the following exception:</p>
  
  <pre><code>[*] 00000088 SystemErr     R Caused by: org.eclipse.jst.j2ee.commonarchivecore.internal.exception.NoModuleFileException: A file does not exist for module element having uri: core-api.jar
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.checkType(ModuleRefImpl.java:591)
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.initModuleFileFromEAR(ModuleRefImpl.java:167)
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getModuleFile(ModuleRefImpl.java:120)
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getModuleFile(EARFileImpl.java:165)
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EARFileImpl.getDeploymentDescriptor(EARFileImpl.java:817)
  [*] 00000088 SystemErr     R    at org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ModuleRefImpl.getDeploymentDescriptor(ModuleRefImpl.java:230)
  [*] 00000088 SystemErr     R    ... 49 more
  </code></pre>
  
  <p>I am using Websphere Test Environment v8.5.5.0</p>
  
  <p><s><strong>UPDATE:</strong> I suspected maybe the compression algorithm used to zip the ear file may be to blame and it seems as though I was right; unzipping and rezipping the ear file using 7zip caused the deployment to work without errors.</p>
  
  <p>I am using gradle as a build tool which provides it's own mechanism for zipping archives. I have tried setting the <code>entryCompression</code> mode to <code>ZipEntryCompression.STORED</code> without success.</p>
  
  <p>This leads me to a new question: </p>
  
  <ol>
  <li><p>How can i control the assembly/compression of the ear file to conform with what Websphere expects?</p>
  
  <p>and</p></li>
  <li><p>What method does gradle use to compress the ear?</p></li>
  </ol>
  
  <p><strong>UPDATE 2:</strong> Looking at the gradle source code, I can see the Zip implementation uses ant's <code>org.apache.tools.zip.ZipOutputStream</code> (1.9.3). has anyone had difficulty with this process before?</s></p>
  
  <p><strong>UPDATE 3:</strong> It seems as if I've been chasing a red herring. I have inspected the file that supposedly deployed correctly and saw that the ear contained an extra folder level above the root of the ear (that is <code>app.ear!app/&lt;root&gt;</code>).</p>
  
  <p>assuming that compression algorithms have nothing to do with it, does anyone have any ideas?</p>
  
  <p><strong>UPDATE 4:</strong> Ok, I'm really close, I managed to get the deployment working after inspecting some sample ear files and testing various theories. <s>I did these things and it worked</s> (see Update 5).</p>
  
  <ul>
  <li>Instead of java modules in the application.xml i have ejb modules</li>
  <li>I included a basic META-INF/ejb-jar.xml file in the core.jar (even though the spec says you don't need them) as websphere apparently does not like it when it's missing</li>
  <li>I removed the core-api.jar module from the application.xml</li>
  </ul>
  
  <p>So i now have the following application.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;application ...&gt;
    &lt;application-name&gt;MyApp&lt;/application-name&gt;
    &lt;display-name&gt;My App&lt;/display-name&gt;
    &lt;module id="mod 1"&gt;
      &lt;ejb&gt;core.jar&lt;/ejb&gt;
    &lt;/module&gt;
    &lt;module id="mod 2"&gt;
      &lt;web&gt;
        &lt;web-uri&gt;web.war&lt;/web-uri&gt;
        &lt;context-root&gt;/&lt;/context-root&gt;
      &lt;/web&gt;
    &lt;/module&gt;
    &lt;library-directory&gt;lib&lt;/library-directory&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>One last question: how can i 'deploy' an  artifact to an ear project without adding it to the application xml? alternatively, how can i customize the application.xml after the deployments have been resolved?</p>
  
  <p><strong>UPDATE 5:</strong> Apologies for the fluctuating state of my question. </p>
  
  <p>Although the application successfully deployed, it did not start up, giving me an error saying that my ejb jars had no ejbs. I have since decided, following the advice I have received and also an answer below, that my spring-based jars are classed as "utility" jars and should live in the lib folder.</p>
  
  <p>I am expecting to use these jars in EJBs in the future and so wish to keep them in the lib folder instead of directly in the war.</p>
  
  <p>this is my final application.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;application ...&gt;
    &lt;application-name&gt;MyApp&lt;/application-name&gt;
    &lt;display-name&gt;My App&lt;/display-name&gt;
    &lt;module&gt;
      &lt;web&gt;
        &lt;web-uri&gt;web.war&lt;/web-uri&gt;
        &lt;context-root&gt;/&lt;/context-root&gt;
      &lt;/web&gt;
    &lt;/module&gt;
    &lt;library-directory&gt;lib&lt;/library-directory&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>Thank you for your time and patience.</p>