Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Resolved] Load a external jar with entities and persistence.xml(Load persistence specifications from a jar outside the project)
[Resolved] Load a external jar with entities and persistence.xml [message #655959] Wed, 23 February 2011 14:44 Go to next message
Alberto  is currently offline 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 15: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 15:19 Go to previous message
Alberto  is currently offline 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..
Previous Topic:Custom reverse engineering strategy
Next Topic:Performance issues persisting large amounts of similar entities
Goto Forum:
  


Current Time: Tue Sep 30 11:58:47 GMT 2014

Powered by FUDForum. Page generated in 0.02376 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software