如何在jar文件的类路径中配置C3p0.properties文件以读取类路径外的C3P0-config.xml

时间:2014-02-12 18:21:55

标签: java c3p0

可能是我错误地表达了这个问题,但这是问题所在。我有一个名为util的库,在util中我们有一个数据库类,它将使用C3P0进行数据库连接。该util库由团队中的不同开发人员使用。

为了让每个人的生活更轻松,因为我们有一个模块化系统,系统中的每个模块都可以指定它自己的数据库连接和属性,因为它认为适合他们的模块。我们这样做的唯一原因是因为调用执行查询的方法都是在这个库中定义的,所以不是每个人一遍又一遍地重写相同的代码,使用具有该功能的共享库非常有效。

当前的设置是我在util库类路径中有C3P0.properties文件,在其中我已经像这样定义了C3P0-config.xml文件的路径。

com.mchange.v2.c3p0.cfg.xml =。/ CONF / C3P0-config.xml中

然后我构建了jar并将其交给其他开发者。然后,他们在应用程序中创建一个conf目录并添加c3p0-config.xml。 目录的结构看起来像这样

Parent directory - module name {

Sub directories

-lib  -> {Util.jar & other jars}

-conf -> {c3p0-config.xml & other config files}

-logs

-modulename.jar

}

在执行jar文件时,我们收到错误

2014-02-12 20:50:59 INFO  MLog:124 - MLog clients using log4j logging.
2014-02-12 20:50:59 DEBUG MLog:101 - Could not find resource path text file for path '/com/mchange/v2/cfg/vmConfigResourcePaths.txt'. Skipping.
2014-02-12 20:50:59 DEBUG MLog:101 - Added paths from resource path text file at '/mchange-config-resource-paths.txt'
2014-02-12 20:50:59 DEBUG MLog:101 - Reading VM config for path list /com/mchange/v2/log/default-mchange-log.properties, /mchange-commons.properties, /c3p0.properties, hocon:/reference,/application,/c3p0,/, /mchange-log.properties, /
2014-02-12 20:50:59 DEBUG MLog:101 - The configuration file for resource identifier '/mchange-commons.properties' could not be found. Skipping.
java.io.FileNotFoundException: Resource not found at path '/mchange-commons.properties'.
    at com.mchange.v2.cfg.BasicPropertiesConfigSource.propertiesFromSource(BasicPropertiesConfigSource.java:64)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.firstInit(BasicMultiPropertiesConfig.java:185)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.<init>(BasicMultiPropertiesConfig.java:110)
    at com.mchange.v2.cfg.ConfigUtils.read(ConfigUtils.java:63)
    at com.mchange.v2.cfg.ConfigUtils.readVmConfig(ConfigUtils.java:115)
    at com.mchange.v2.cfg.MLogConfigSource.readVmConfig(MLogConfigSource.java:46)
    at com.mchange.v2.log.MLogConfig.refresh(MLogConfig.java:59)
    at com.mchange.v2.log.MLog.refreshConfig(MLog.java:59)
    at com.mchange.v2.log.MLog.<clinit>(MLog.java:51)
    at com.mchange.v2.naming.JavaBeanReferenceMaker.<clinit>(JavaBeanReferenceMaker.java:51)
    at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<clinit>(PoolBackedDataSourceBase.java:260)
    2014-02-12 20:50:59 DEBUG MLog:101 - The configuration file for resource identifier 'hocon:/reference,/application,/c3p0,/' could not be found. Skipping.
java.io.FileNotFoundException: HOCON lib (typesafe-config) is not available. Also, no resource available at '/reference,/application,/c3p0,/' for HOCON identifier 'hocon:/reference,/application,/c3p0,/'.
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.configSource(BasicMultiPropertiesConfig.java:86)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.firstInit(BasicMultiPropertiesConfig.java:184)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.<init>(BasicMultiPropertiesConfig.java:110)
    at com.mchange.v2.cfg.ConfigUtils.read(ConfigUtils.java:63)
    at com.mchange.v2.cfg.ConfigUtils.readVmConfig(ConfigUtils.java:115)
    at com.mchange.v2.cfg.MLogConfigSource.readVmConfig(MLogConfigSource.java:46)
    at com.mchange.v2.log.MLogConfig.refresh(MLogConfig.java:59)
    at com.mchange.v2.log.MLog.refreshConfig(MLog.java:59)
    at com.mchange.v2.log.MLog.<clinit>(MLog.java:51)
    at com.mchange.v2.naming.JavaBeanReferenceMaker.<clinit>(JavaBeanReferenceMaker.java:51)
    at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<clinit>(PoolBackedDataSourceBase.java:260)
2014-02-12 20:50:59 DEBUG MLog:101 - The configuration file for resource identifier '/mchange-log.properties' could not be found. Skipping.
java.io.FileNotFoundException: Resource not found at path '/mchange-log.properties'.
    at com.mchange.v2.cfg.BasicPropertiesConfigSource.propertiesFromSource(BasicPropertiesConfigSource.java:64)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.firstInit(BasicMultiPropertiesConfig.java:185)
    at com.mchange.v2.cfg.BasicMultiPropertiesConfig.<init>(BasicMultiPropertiesConfig.java:110)
    at com.mchange.v2.cfg.ConfigUtils.read(ConfigUtils.java:63)
    at com.mchange.v2.cfg.ConfigUtils.readVmConfig(ConfigUtils.java:115)
    at com.mchange.v2.cfg.MLogConfigSource.readVmConfig(MLogConfigSource.java:46)
    at com.mchange.v2.log.MLogConfig.refresh(MLogConfig.java:59)
    at com.mchange.v2.log.MLog.refreshConfig(MLog.java:59)
    at com.mchange.v2.log.MLog.<clinit>(MLog.java:51)
    at com.mchange.v2.naming.JavaBeanReferenceMaker.<clinit>(JavaBeanReferenceMaker.java:51)
    at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<clinit>(PoolBackedDataSourceBase.java:260)

可能是什么问题?我做错了什么?

1 个答案:

答案 0 :(得分:3)

在您显示的日志消息和堆栈跟踪中,没有任何错误。这些都是DEBUG级别的消息。通常应在c3p0记录com.mchangeINFO个图书馆。)

c3p0&amp; mchange-commons-java检查许多不同地方的潜在配置信息。在许多地方,他们什么也没找到,所以继续前进。在DEBUG进行记录,您正在查看/mchange-log.properties中图书馆检查的过程,例如CLASSPATH,但未能找到它。在DEBUG,库记录了他们看到的,他们没有找到的,以及未找到的异常。

这一切都不关心。这是正常的。

主要问题是配置用户是否放入c3p0-config.xml。您正在使用文件的相对目录,而不是绝对文件系统位置。我认为这将有效,相对被解释相对于进程的工作目录,但我不确定它是否会工作,即使它确实如此,你确定它不会脆弱,取决于用户的方式启动你的过程?用户是否会运行一个脚本来确保正确的工作目录?