title: Webapp cannot find Persistence Unit. No persistence unit named 'X' is available in scope
body: <p>I am trying to run my webapp on my weblogic 12c server using EJB 3.1, JPA 2.0, M2E-WTP, and JSF 2.1 technologies and continue to get the following error:</p>
  
  <pre><code>javax.ejb.EJBException: EJB
  Exception: : java.lang.IllegalArgumentException: No persistence unit named 'X'
  is available in scope Webapp. Available persistence units: [] at
  weblogic.persistence.ModulePersistenceUnitRegistry
  .getPersistenceUnit(ModulePersistenceUnitRegistry.java:130) at
  weblogic.persistence.BasePersistenceContextProxyImpl
  .&lt;init&gt;(BasePersistenceContextProxyImpl.java:40) at
  weblogic.persistence.TransactionalEntityManagerProxyImpl
  .&lt;init&gt;(TransactionalEntityManagerProxyImpl.java:31) at
  weblogic.persistence.EntityManagerInvocationHandlerFactory.
  createTransactionalEntityManagerInvocationHandler
  (EntityManagerInvocationHandlerFactory.java:20) at 
  weblogic.persistence.PersistenceManagerObjectFactory
  .createPersistenceContextProxy(PersistenceManagerObjectFactory.java:66) at 
  weblogic.persistence.PersistenceManagerObjectFactory
  .getObjectInstance(PersistenceManagerObjectFactory.java:31) at 
  javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
  at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:251) at
  weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:406) at
  weblogic.j2eeclient.java.ClientReadOnlyContextWrapper.lookup
  </code></pre>
  
  <p>This is the EJBBean that is triggering the exception</p>
  
  <pre><code>@Stateless
  public class QuoteSessionEJB implements QuoteSessionEJBLocal {
  
  /**
   * Default constructor. 
   */
  public QuoteSessionEJB() {
      // TODO Auto-generated constructor stub
  }
  
  @PersistenceContext(unitName="X")
  private EntityManager em;
  /**
  * Returns a list of Quote objects in the database
  * @return List&lt;Customer&gt;
  */
  public List&lt;Quote&gt; getQuote() {
  Query query = em.createNamedQuery("findQuotes");
  return query.getResultList();
  }
  
  }
  </code></pre>
  
  <p>Here is the persistence.xml file which is located under src/main/java --> META-INF which eclipse built.</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>I have spent hours searching the web for answers with no avail. I don't understand why  the persistence unit X in my persistence.xml cannot be located...</p>
  
  <p>I'm hoping someone has ran into this same problem or know hows to fix it.
  Any help is greatly appreciated!</p>
  
  <p><strong>Update:</strong> Per better_use_mkstemp comment below I moved the META-INF folder containing my persistence.xml from src/main/java to WEB-INF/classes. I have to create the classes folder in eclipse. This worked! Much appreciated!</p>
  
  <p><strong>Following up question:</strong> Doing some more research I found that putting the META-INF folder in src/main/resources would also solve the problem, however it did not. I dont know if this is an issue with Maven's M2E-WTP eclipse plugin or I am simply misunderstanding something here. Below is a screen shot of the folder structure.</p>
  
  <p><img src="https://i.stack.imgur.com/Ebecg.jpg" alt="enter image description here"></p>
  
  <p>By browsing the war file the maven install command creates, I can see that the META-INF folder IS correctly placed in the WEB-INF/classes folder. But simply publishing to the server within Eclipse does not work. Unless I manually create the classes folder under WEB-INF and manually drop/move the META-INF folder in there I can't get it to work inside the IDE. Also it doesn't seem to make sense to have a copy of the META-INF folder in two places as a solution.</p>