如何配置C3p0。在jar文件的类路径中,属性文件读取C3P0-config。xml在类路径中

时间:2022-06-13 11:00:58

May be I have phrased the question wrongly but here's the issue. I have a library called util, inside util we have a database class that will be using C3P0 for database connectivity. This util library is used by different devs within the team .

可能是我错误地表达了这个问题,但问题是这样的。我有一个名为util的库,在util内部有一个数据库类,它将使用C3P0进行数据库连接。这个util库是由团队中的不同devs使用的。

To make life easier for everyone since we have a modular system, each module in the system can specify it's own database connection and properties as it sees fit for their module. The only reason we are doing this is because the methods for calling executing queries are all defined in this libraries and so instead of everyone rewriting the same code over and over it's much efficient to use a shared lib with that functionality.

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

The current set up is that I have the C3P0.properties file inside my util library classpath and inside it I have defined the path of the C3P0-config.xml file like this.

现在设置的是C3P0。属性文件在我的util库类路径中,在其中我定义了C3P0-config的路径。这样的xml文件。

com.mchange.v2.c3p0.cfg.xml=./conf/c3p0-config.xml

/ conf / c3p0-config.xml com.mchange.v2.c3p0.cfg.xml =

I then build and the jar and give it to the rest of the devs . They then create a conf directory in their application and add the c3p0-config.xml. The Strucuture of the Directory looks like this

然后我把它建好,然后把它交给其他的devs。然后,他们在应用程序中创建一个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

}

On executing the jar file we get the error

在执行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)

What could be the problem ? What I'm I doing wrong ?

有什么问题吗?我做错了什么?

1 个解决方案

#1


3  

In the log messages and stack traces that you've shown, there is nothing wrong at all. These are all DEBUG level messages. (c3p0 & com.mchange libraries should usually be logged at INFO.)

在您显示的日志消息和堆栈跟踪中,没有任何错误。这些都是调试级消息。(c3p0 & com。mchange库通常应该记录在信息中。

c3p0 & mchange-commons-java check for potential config information in lots of different places. In many of those places, they find nothing, and so move on. Logging at DEBUG, you are watching the process of libraries checking for, e.g., /mchange-log.properties, in the CLASSPATH and failing to find it. At DEBUG, the libraries log that they looked, that they did not find, and the Exception that went along with not finding.

c3p0 & mchange-common -java检查许多不同地方的潜在配置信息。在很多地方,他们什么也没找到,所以继续前进。在调试过程中,您正在观察库检查的过程,例如,/mchange-log。属性,在类路径中并没有找到它。在调试过程中,他们查找的库日志,他们没有找到,以及没有找到的异常。

None of this is of concern at all. It is normal.

这些都不是令人担忧的。这是正常的。

The main question is whether the config users put in c3p0-config.xml is taking. You are using a relative directory for the file, rather than an absolute filesystem location. I presume that will work, with relative being interpreted relative to the working directory of the process, but I'm not sure it will work, and even if it does, are you sure that it won't be fragile, depend on how users start up your process? Will users run a script that will ensure the proper working directory?

主要的问题是配置用户是否放入了c3p0-config。xml是服用。您使用的是文件的相对目录,而不是绝对的文件系统位置。我认为这是可行的,相对于流程的工作目录,我不确定它是否可行,即使有,您确定它不会很脆弱,取决于用户如何启动您的流程?用户会运行一个脚本以确保正确的工作目录吗?

#1


3  

In the log messages and stack traces that you've shown, there is nothing wrong at all. These are all DEBUG level messages. (c3p0 & com.mchange libraries should usually be logged at INFO.)

在您显示的日志消息和堆栈跟踪中,没有任何错误。这些都是调试级消息。(c3p0 & com。mchange库通常应该记录在信息中。

c3p0 & mchange-commons-java check for potential config information in lots of different places. In many of those places, they find nothing, and so move on. Logging at DEBUG, you are watching the process of libraries checking for, e.g., /mchange-log.properties, in the CLASSPATH and failing to find it. At DEBUG, the libraries log that they looked, that they did not find, and the Exception that went along with not finding.

c3p0 & mchange-common -java检查许多不同地方的潜在配置信息。在很多地方,他们什么也没找到,所以继续前进。在调试过程中,您正在观察库检查的过程,例如,/mchange-log。属性,在类路径中并没有找到它。在调试过程中,他们查找的库日志,他们没有找到,以及没有找到的异常。

None of this is of concern at all. It is normal.

这些都不是令人担忧的。这是正常的。

The main question is whether the config users put in c3p0-config.xml is taking. You are using a relative directory for the file, rather than an absolute filesystem location. I presume that will work, with relative being interpreted relative to the working directory of the process, but I'm not sure it will work, and even if it does, are you sure that it won't be fragile, depend on how users start up your process? Will users run a script that will ensure the proper working directory?

主要的问题是配置用户是否放入了c3p0-config。xml是服用。您使用的是文件的相对目录,而不是绝对的文件系统位置。我认为这是可行的,相对于流程的工作目录,我不确定它是否可行,即使有,您确定它不会很脆弱,取决于用户如何启动您的流程?用户会运行一个脚本以确保正确的工作目录吗?