| [Resolved] Load a external jar with entities and persistence.xml [message #655959] |
Wed, 23 February 2011 09:44  |
Alberto Messages: 7 Registered: February 2011 |
Junior Member |
|
|
Hi friends..
I have a question about eclipselink and jpa in general:
I have a jar with the entities and the persistence.xml.. nothing unusual you can say..
Ok the thing is that the jar is outside the classpath..
With the classloader, I've no problem to load the entity classes.. the problem is to load the peristence.xml..
So the question is: is there a way to load the persistence.xml from a location in the file system?
Thanks..
[Updated on: Thu, 24 February 2011 10:21] Report message to a moderator
|
|
|
| Re: Load a external jar with entities and persistence.xml [message #656215 is a reply to message #655959] |
Thu, 24 February 2011 10:19  |
Alberto Messages: 7 Registered: February 2011 |
Junior Member |
|
|
Hi friends..
i've rosolved my problem..
The method that look for the persistence.xml is org.eclipse.persistence.internal.jpa.deployment.PersistenceU nitProcessor.findPersistenceArchives .. It calls the classLoader's method getResources that finds the resource with a given name (in this case "META-INF/persistence.xml" ).. So my solution is to override the classloader's method getResources in this way
public Enumeration<URL> getResources(String descriptorPath) throws IOException{
if(descriptorPath.equals("META-INF/persistence.xml")){
String s = jar.getAbsolutePath().replace('\\', '/');
final URL jarUrl = new URL("jar","",-1,"file:/"+s+"!/META-INF/persistence.xml");
return new Enumeration<URL>() {
private int position = 0;
public boolean hasMoreElements() {
return position>=0;
}
public URL nextElement() {
if(position<0)
throw new NoSuchElementException();
position --;
return jarUrl;
}
};
}else{
return super.getResources(descriptorPath);
}
}
I hope it can help..
|
|
|
Powered by
FUDForum. Page generated in 0.61685 seconds