在普通的java应用程序中从context.xml创建InitialContext

时间:2016-02-03 13:36:06

标签: java jndi initial-context

正如问题所暗示的,我有一个简单的java应用程序(又名“简单主”)需要初始化其信息在context.xml中的hibernate连接。

经过大量的搜索和一些黑客攻击from here后,我得出结论:

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?我对手动解析文件不感兴趣,我可以自己做。

0 个答案:

没有答案