I have standalone Java application using JPA. I'm looking to load persistance.xml file from user configured folder. I know JPA vendor checks for meta-inf folder and loads it automatically.
Using this way mentioned below, it is working from any folder path inside the source folder but its not working if I need to load it from other project folders other than source folders. For my application, config folder will be in root folder of project or I might need to get from URL.
properties.put("eclipselink.persistencexml", "config/persistence.xml");
Also, i tried with this classloader overwriting mechanism and it didn't work.
Thread.currentThread().setContextClassLoader(new ClassLoader() {
@Override
public Enumeration<URL> getResources(String name) throws IOException
{
if (name.equals("META-INF/persistence.xml")) {
return Collections.enumeration(Arrays.asList(new File("/config/persistence.xml").toURI().toURL()));
}
return super.getResources(name);
}
});
I will need to load persistance.xml manually from folder other than folder from source where classloader is scanning for classes. Does anybody know how to do it with eclipselink/toplink JPA in non-applicaiton server related environments?
Map properties = new HashMap();
//properities
properties.put("eclipselink.************", "*****");
javax.persistence.EntityManagerFactory emf_myDB=javax.persistence.Persistence.createEntityManagerFactory(DB_PERSISTENCE_UNIT_NAME, properties);