netbeans 和 hibernate 配置
如何从配置文件动态加载休眠的配置信息。 Netbeans 目前将该信息硬编码到 xml 文件中,然后将该文件编译到 jar 中。我是来自 PHP 领域的 Java/Netbeans 新手,并且习惯于从 .ini 或类似内容中提取的中央引导程序,但 Netbeans 倾向于在生成模型等时将这些信息硬编码在 xml 文件中,该文件是然后编译进jar里。我正在寻找使用各种数据库配置为各种客户端计算机设置配置的传统方法。我不想在必须安装该应用程序的每台计算机上编译该应用程序。
How can I load the configuration information for hibernate dynamically from a config file. Netbeans currently hard codes that information into an xml file that is then compiled into the jar. I'm a newbie to Java/Netbeans coming from PHP land and am use to a central bootstrap that pulls from a .ini or something similar, but netbeans tends to hardcode this information upon generation of the models,etc in an xml file that is then compiled in the jar. I'm looking for conventional methods of setting up configuration for various client machines using various database configurations. I don't want to have to compile the app on each machine it must be installed on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Configuration 类读取配置文件。默认情况下,它使用类路径中找到的 hibernate.cfg.xml 文件,但您可以使用 以文件为参数的配置方法,并将配置文件存储在文件系统上而不是jar中。
您还可以将静态映射(配置之间永远不会更改)放入 jar 内的文件中,并将变化的配置放入外部文件中。查看配置的 javadoc 以了解如何将资源和配置文件添加到配置中。
The configuration file is read using the Configuration class. By default, it uses the hibernate.cfg.xml file found in the classpath, but you can use the configure method taking a file as parameter, and store the config file on the file system rather than in the jar.
You can also put the static mapping, which never changes between configs, in a file inside the jar, and put the varying config inside an external file. Look at the javadoc for Configuration to know how to add resources and config files to the configuration.