Reputation: 2031
As the question implies, I have a simple java app (aka a "simple main") that needs to initialize a hibernate connection whose information is in context.xml
.
After lots of searching and with some hacks from here I concluded to this:
public static void main(String[] args) {
//JNDI provider is needed and RMI registry has one...
try {
java.rmi.registry.LocateRegistry.createRegistry(1099);
System.out.println("RMI registry ready.");
} catch (Exception e) {
System.out.println("Exception starting RMI registry:");
e.printStackTrace();
}
new InitialContext().readContextXml("context.xml");//of course there is nothing like that. But is there an equivalent?
String result = thatWillConnectWithHibernate();
System.out.println(result);
}
private static String thatWillConnectWithHibernate() {
//does stuff
}
So is there a simple way to create an InitialContext from an xml file? I'm not interested in parsing the file manually, I can do that my self.
Upvotes: 5
Views: 312