在普通java应用程序中从context.xml创建InitialContext
正如问题所暗示的,我有一个简单的java应用程序(也称为“simple main”),需要初始化hibernate连接,其信息位于在普通java应用程序中从context.xml创建InitialContext,java,jndi,initial-context,Java,Jndi,Initial Context,正如问题所暗示的,我有一个简单的java应用程序(也称为“simple main”),需要初始化hibernate连接,其信息位于context.xml中 经过大量的搜索和一些技巧,我得出以下结论: public static void main(String[] args) { //JNDI provider is needed and RMI registry has one... try { java.rmi.registry.LocateRegistry.
context.xml
中
经过大量的搜索和一些技巧,我得出以下结论:
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
}
那么,有没有一种从xml文件创建InitialContext的简单方法呢?我对手动解析文件不感兴趣,我可以自己做