We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

ubutuntu tomcat db connection pool

JianJunShen
JianJunShen asked
on
Medium Priority
1,094 Views
Last Modified: 2012-06-27
I have a struts 2, hibernate, spring, tomcat 5, Mysql test application. After I deploy it in Linxu unbuntu, I got following waring in the catalina.log file:

WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load
 resource factory class [Root exception is java.lang.ClassNotFoundException: org
.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

Tomcat is installed by apt-get install tomcat...
I have put mysql-connector-java-3.1.10-bin, commons-dbcp-1.2.2.jar  into /usr/share/tomcat5.5/common/lib/. I also change access right two both jars as 777 (Wow, it is too much!).

Though tomcat is installed /var/lib/tomcat5.5.

Why do I get warning message since I have put jars in the lib directory? Isn't tomcat will automatically load all jars in usr/share/tomcat5.5/common/lib/ directory?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
>>usr/share/tomcat5.5/common/lib/

Shouldn't that be

usr/share/tomcat5.5/lib/  ?
CERTIFIED EXPERT
Top Expert 2016
Commented:
No - i think that should be OK. Make sure that class is actually in the dbcp jar

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try putting dbcp it in WEB_INF/lib

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
>  I also change access right two both jars as 777

stop doing that ;)

CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to get it working in a common lib. There's no point in filling up your HD by copying dbcp into every webapp
put dbcp.jar into /usr/share/tomcat-5/lib
http://bugs.gentoo.org/show_bug.cgi?id=144276

Author

Commented:
there is no /usr/share/tomcat-5/lib directory. Do I need to create it?
/common/lib/ failed. try. even if it's weird, since the installation should have created the right dirs for it to search for libs

Author

Commented:
I got same error.

Feb 10, 2009 12:53:08 PM org.apache.catalina.core.NamingContextListener addResou
rce
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load
 resource factory class [Root exception is java.lang.ClassNotFoundException: org
.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

As you see, I have put dbcp jar into lib. Does that enough?
:/usr/share/tomcat5.5/lib$ ls -al
total 548
drwxr-xr-x 2 juhanishen juhanishen   4096 2009-02-10 12:51 .
drwxrwxrwx 6 root       root         4096 2009-02-10 12:47 ..
-rwxrwxrwx 1 root       root       121757 2009-02-10 12:51 commons-dbcp-1.2.2.jar
-rwxrwxrwx 1 root       root       418698 2009-02-10 12:51 mysql-connector-java-3.1.10-bin.jar
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
your mysql driver should be in common/lib
and try dbcp in <webapp>/WEB-INF/lib

Author

Commented:
Those two jars are located both in <webapp>/WEB-INF/lib and /usr/share/tomcat5.5/lib/.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
just have them in each in one place
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
actually it (dbcp) should have already been in place. So put it back in common/lib
And put mysql driver also in common/lib
and put back anything else you have moved :)

Author

Commented:
same error:

Feb 10, 2009 1:13:29 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load res
ource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.
tomcat.dbcp.dbcp.BasicDataSourceFactory]


Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
> .apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

try changing your context to use:

.apache.tomcat.dbcp.BasicDataSourceFactory
CERTIFIED EXPERT
Top Expert 2016
Commented:
Please post result of
jar tf /usr/share/tomcat5.5/common/lib/commons-dbcp-1.2.2.jar | grep BasicDataSourceFactory

Open in new window

Author

Commented:
Same error:

Feb 10, 2009 1:44:56 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException:
org.apache.tomcat.dbcp.BasicDataSourceFactory]

Does this matter:I notice following two jars in /usr/share/tomcat5.5/common/lib has no executable rights.

-rw-r--r-- 1 root root  36774 2008-10-20 18:02 naming-factory.jar
-rw-r--r-- 1 root root  47692 2008-10-20 18:02 naming-resources.jar
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>Does this matter:I notice following two jars in /usr/share/tomcat5.5/common/lib has no executable rights.

No

What was the result of the command i posted?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
try:

org.apache.commons.dbcp.BasicDataSourceFactory

Author

Commented:
CEHJ:

It is org/apache/commons/dbcp/BasicDataSourceFactory.class

Author

Commented:
Objects:

Same error:

Feb 10, 2009 2:10:40 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory clas
s [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.BasicDataSourceFactory]

I am afraid this is tomcat ubuntu bug.
CERTIFIED EXPERT
Top Expert 2016

Commented:
There still could be something wrong with perms though. Could you post the result of the following please?
ls -l /usr/share/tomcat5.5/common

Open in new window

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
don't think so we use tomcat + ubuntu with many clients

Author

Commented:
CEHJ:

Here comes the log:

/usr/share/tomcat5.5/logs$ ls -l /usr/share/tomcat5.5/common/
total 16
drwxr-xr-x 2 root root 4096 2008-10-20 18:02 classes
drwxr-xr-x 2 root root 4096 2008-10-20 18:02 endorsed
drwxr-xr-x 2 root root 4096 2009-02-07 01:04 i18n
drwxr-xr-x 2 root root 4096 2009-02-10 14:04 lib
CERTIFIED EXPERT
Top Expert 2016

Commented:
Hmm. If those are all owned by root, i suspect that other parts of the tree are too. If you're not running as root (not a good idea to run as root), that could cause problems down the line, though i'm not sure how it could cause the classloading problem you have currently.

Author

Commented:
How to run as a root?

Author

Commented:
When I install tomcat5.5, I am using command
sudo apt-get install tomcat5.5

What's the other way around? Now How could I uninstall tomcat5.5 and use command:
apt-get install tomcat5.5 to install tomcat5.5 or simply download tomcat5.5 package by myself?

CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to see how your system starts up Tomcat and set the user to root. You could try first by starting Tomcat as root, but it might still run as another user - see if it does
CERTIFIED EXPERT
Top Expert 2016

Commented:
You can't install software as anyone other than root. Anyway on your system, the Tomcat tree is not owned by root - you've changed it.

You could uninstall and start again

Author

Commented:
I use sudo /etc/init.d/tomcat5.5 start to start tomcat. I donot know how to set the user as root. Could you please guide me? I am new to Linux.

CERTIFIED EXPERT
Top Expert 2016

Commented:
Personally i would reinstall it - the tree has been too disturbed

Author

Commented:
Are there straightforward way to uninstall it? In windows, there is Add/Remove program.
CERTIFIED EXPERT
Top Expert 2016
Commented:
sudo apt-get remove tomcat

Author

Commented:
I used command sudo apt-get remove tomcat5.5, initially it does not remove all directory, for example, /etc/tomcat5.5, /etc/init.d/tomcat5.5, I manually delete them. Then I installed tomcat again by command sudo apt-get install tomcat5.5, now there is no tomcat5.5 under /etc/init.d/directory. There is no common directory under /usr/share/tomcat5.5/ directory. What happens?
CERTIFIED EXPERT
Top Expert 2016

Commented:
Try it again with


sudo apt-get remove --purge tomcat5.5

Open in new window

Author

Commented:
I reinstalled tomcat5.5, and I am now could start tomcat from /usr/share/tomcat5.5/bin.
Just by call ./startup.sh.
The log is as follows:

:/usr/share/tomcat5.5/bin$ ./startup.sh
classpath is :/usr/share/tomcat5.5/bin/bootstrap.jar:/usr/share/tomcat5.5/bin/commons-logging-api.jar:/usr/share/tomcat5.5/common/lib/commons-dbcp.jar:/usr/share/tomcat5.5/common/lib/mysql-connector-java-3.1.10-bin.jar
Using CATALINA_BASE:   /usr/share/tomcat5.5
Using CATALINA_HOME:   /usr/share/tomcat5.5
Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp
Using JRE_HOME:       /usr/lib/jvm/java-6-openjdk

Same warning info:
Feb 10, 2009 11:49:04 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

I also tried org.apache.tomcat.dbcp.BasicDataSourceFactory. it has similar warning message.

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
> How to run as a root?

do *not* run tomcat as root
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
> I used command sudo apt-get remove tomcat5.5

there is no need to remove a package


could you try removing the factory name from your context definition and let me know how it goes

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
and check the config of all your listeners to make sure they are starting up ok

Commented:
Morning , I think , org.apache.tomcat.dbcp.BasicDataSourceFactory is not in  mysql-connector-java-3.1.10-bin or commons-dbcp-1.2.2.jar libs,  it is specific tomcat resource factory and u need see it in tomcat default env.
I'd strongly suggest you remove that one and use a real Tomcat download:
http://tomcat.apache.org/download-55.cgi
http://tomcat.apache.org/download-60.cgi
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>it is specific tomcat resource factory

Doh! I didn't notice that in my request for a Java listing before!

Author

Commented:
Yes. Objects has the same idea as vahana. And I tested it works now. Thanks a lot for all of your contribution.

Author

Commented:
The problem is only 500 points. I wish I could give you 5000 points. Wow!
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
CERTIFIED EXPERT
Top Expert 2016

Commented:
JianJunShen, this suggests the package could be broken. What exactly did you do to fix it - did you download Tomcat from elsewhere?

Author

Commented:
CEHJ:

There is one point that package is broken. Objects help me fixed it. It is spring xml, bean definition. You are right!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.