title: How do I load database credentials from a properties file in JPA?
body: <p>So I have a Java/JPA2.0 (EclipseLink) app that connects to a MySQL database.  My intention is just passing a JAR file around with a <code>db.properties</code> file.  The <code>db.properties</code> should contain the server host address, username, password, etc so that the end user can just plug that in and start using the JAR in their projects.</p>
  
  <p>Currently, I just used Netbeans to create a <code>persistence.xml</code> file with the credentials and that works.  But how do I implement the properties file?</p>
  
  <p>My EntityManager class:</p>
  
  <pre><code>public class Factories {
  
      private static final EntityManagerFactory entityManagerFactory = buildEntityManagerFactory();
  
          private static EntityManagerFactory buildEntityManagerFactory() {
              try {
                  return Persistence.createEntityManagerFactory("MyPU");
              } catch (Exception ex) {
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static EntityManager getEntityManager() {
          return entityManagerFactory.createEntityManager();
      }
  }
  </code></pre>
  
  <p>Thanks</p>