title: JPA persistence.xml META-INF not working correctly
body: <p>I am stumped when it comes to the location of my persistence.xml file. I am using eclipselink 2.4 as my JPA 2.0 implementation and have my persistence.xml located under src/main/resources/META-INF/persistence.xml as many posts state.</p>
  
  <p><strong>The first issue:</strong> After publishing to my server inside eclipse I get an error stating that my persistence.xml is not found.</p>
  
  <pre><code>Exception: : java.lang.IllegalArgumentException: No persistence unit named 'X'
  is available in scope Webapp. Available persistence units: [] at
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/AGmSc.png" alt="enter image description here"></p>
  
  <p>Here is the code for my persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
  http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  &lt;persistence-unit name="X" transaction-type="JTA"&gt;
  &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
  &lt;jta-data-source&gt;localJTA&lt;/jta-data-source&gt;
  &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
  &lt;properties&gt;
      &lt;property name="eclipselink.target-server" value="WebLogic"/&gt;
      &lt;property name="eclipselink.logging.level" value="FINEST"/&gt;          
  &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>If I move the META-INF to webapp/WEB-INF/classes/META-INF then it works! I cannot understand what the problem is.</p>
  
  <p><img src="https://i.stack.imgur.com/delbz.png" alt="enter image description here"></p>
  
  <p>I checked the projects build path and everything looks good there.</p>
  
  <p><img src="https://i.stack.imgur.com/oPxIN.png" alt="enter image description here"></p>
  
  <p><strong>The second issue</strong> I am having is that my annotated entity class is not being picked up automatically by eclipselink. In my JPA config I have Discover annotated classes automatically selected. </p>
  
  <p><img src="https://i.stack.imgur.com/9Fxkk.png" alt="enter image description here"></p>
  
  <p>I also have the following in my xml</p>
  
  <pre><code>&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
  </code></pre>
  
  <p>Technologies used: weblogic 12c server, EJB 3.1, JPA 2.0, M2E-WTP, and JSF 2.1</p>
  
  <p><strong>Update 1:</strong> Leaving META-INF on the path src/main/resources/META-INF/persistence.xml and performing maven install to build the war file, the META-INF folder is correctly placed in WEB-INF/classes/META-INF/persistence.xml like it should be (inside the war). Seems that it is only and issue of when the webapp is built and ran locally in Eclipse. Can anyone explain this?</p>
  
  <p><strong>Update 2:</strong> Leaving META-INF in src/main/resources 
  i.e src/main/resources/META-INF/persistence.xml
  and the following in my persistence.xml rather than explicitly listing the entity class</p>
  
  <pre><code>&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
  </code></pre>
  
  <p>works IF I build the war and deploy it through the weblogic console via internet explorer. Why doesn't it work inside of eclipse!?</p>
  
  <p><strong>Update 3:</strong><br>
  <strong>did you inspect what gets built</strong> -Yes, inside Eclipse I have build set to automatically. Looking in the in the project folder I see java package com, META-INF folder containing persistence.xml, and resources folder which are under Webapp/target/classes.
  <br>
  <strong>If the war is the same</strong> -Are you referring to the Webapp.war folder found in C:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\Weblogic12cDomain_auto_generated_ear_\Webapp.war ? If so the only thing in there is WEB-INF\lib\jsf-impl-2.1.7.jar
  <br>
  <strong>then did you inspect the classpath being used to test your app in Eclipse</strong>- This entry is found in my classpath as expected under Webapp/.classpath 
  <br>
  <strong>if the persistence.xml in the resource directory is on the classpath first, it will be picked up instead of the one in your war or one in the correct directory</strong> - My understanding is Eclipse will building the project, then copy the contents to the server without generating a war file. </p>
  
  <p>Here is what is at the root of the maven generated Webapp.war:</p>
  
  <p><img src="https://i.stack.imgur.com/ax4Cf.png" alt="enter image description here"></p>
  
  <p>Here is what is at the root of the Webapp project folder:</p>
  
  <p><img src="https://i.stack.imgur.com/0Ek3O.png" alt="enter image description here"></p>
  
  <p>Here is what is at the root of the Webapp.war FOLDER under C:\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\Weblogic12cDomain_auto_generated_ear_\Webapp.war</p>
  
  <p><img src="https://i.stack.imgur.com/GN3GZ.png" alt="enter image description here"></p>
  
  <p><strong>if the persistence.xml in the resource directory is on the classpath first, it will be picked up instead of the one in your war or one in the correct directory.</strong>- Not sure what you mean by this. The persistence.xml in my resource/META-INF is the one I want picked up. Not sure what a war file has to do with it? Either way they should be the same persistence.xml I would think.</p>
  
  <p>Any help is MUCH appreciated!! </p>