views:

27

answers:

2

Hi,

I have created an EJB3 project and a JPA project. I'm trying to create a helper class(which will be in a separate project/jar) that will return the Persistence Unit Name from the persistance.xml file which is in the META-INF folder of my JPA project.

How can I read this file as an Input Stream? I can parse the values once I get a reference to this file, but how do I read the files in META-INF folder of a jar from a class of another jar?

Please provide your suggestions.

A: 

If your other jar is in the classpath, you should be able to load this file using: getClass().getResourceAsStream("META-INF/persistence.xml");

Damien
Tried this, but it returned only null for some reason...
whoopy_whale
A: 

This works...

InputStream is = Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml").openStream();
whoopy_whale