469,312 Members | 2,492 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

java.lang.ClassNotFoundException: (Driver Class) While Datasource got using JNDI

dmjpro
2,476 2GB
My context.xml...
Expand|Select|Wrap|Line Numbers
  1. <Context path="/JNDITest">
  2.     <Resource name="jdbc/dataSource" auth="Container"
  3.             type="javax.sql.DataSource"
  4.  
  5.             driverClassName="org.postgresql.Driver"
  6.             url="jdbc:postgresql://10.29.33.90:5432/Admin"
  7.             username="erp"
  8.             password="iiterp"
  9.  
  10.             maxIdle="50"
  11.             maxWait="60000"
  12.             maxActive="10"/>
  13. </Context>
  14.  
My Java Code ....
Expand|Select|Wrap|Line Numbers
  1. Context ctx = new InitialContext();
  2.             DataSource ds= (DataSource)ctx.lookup("java:/comp/env/jdbc/dataSource");
  3.             Connection l_con = ds.getConnection();
  4.  
It's working fine when I use Windows, but it's not working when I use Linux.
My Application server is Tomcat.
I mean to say why does it behave in different operating System .. Where I gone wrong ?
Jan 17 '09 #1
10 6910
JosAH
11,448 Expert 8TB
Is your postgreSQL jar in your classpath on your linux machine?

kind regards,

Jos
Jan 17 '09 #2
dmjpro
2,476 2GB
If the Jar is not in the classpath then why it runs properly in Windows ?

The jars are kept into the the folder WEB-INF/lib and i am making the war file and deploy it into the server...In Windows the war file is running OK ..but why not in Linux?
Jan 19 '09 #3
dmjpro
2,476 2GB
This is my another test ............... in Linux Tomcat Server.
My context.xml is ...
Expand|Select|Wrap|Line Numbers
  1. <Resource name="jdbc/EmployeeDB" auth="Container"
  2.             type="javax.sql.DataSource"
  3.      description="Employees Database for HR Applications"
  4. driverClassName="org.postgresql.Driver"
  5. url="jdbc:postgresql://10.29.32.68:5432/Admin"
  6. username="erp"
  7. password="iiterp"/>
  8.  
In my home.jsp the code snippet is ....
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new org.postgresql.Driver());
  2.             Connection l_con = DriverManager.getConnection("jdbc:postgresql://10.29.32.68:5432/Admin","erp","iiterp");
  3.  
  4.             Context ctx = new InitialContext();
  5.             DataSource ds= (DataSource)ctx.lookup("java:/comp/env/jdbc/EmployeeDB");
  6.             Connection l_con1 = ds.getConnection();
  7.  

When it runs on Linux Tomcat server it shows an error in line ...
Expand|Select|Wrap|Line Numbers
  1. Connection l_con1 = ds.getConnection();
If the jar is not in class path then why it could execute successfully the line ...
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new org.postgresql.Driver());
  2.             Connection l_con = DriverManager.getConnection("jdbc:postgresql://10.29.32.68:5432/Admin","erp","iiterp");
  3.  
  4.  
Please Help!
Jan 19 '09 #4
dmjpro
2,476 2GB
Now I could figure out the problem ...
Actually i didn't deploy into the Tomcat server running under Windows. ;)
Actually what happened, i was using Netbeans simply ran the Application and it got into work .. I don't understand how it did run.
But when i deployed the war file into the Window Tomcat Server then the same problem i was having.
Why does it happen .. when i load the Driver class using DriverManager then it looks from the WEB-INF/ib but when i try to get connection using JNDI look then it looks for another directory?
Jan 19 '09 #5
dmjpro
2,476 2GB
Yeah now it's working i put the driver class into the ext directory.
But still i am waiting for the answer ... why does it behave like differently in two cases ?
Jan 19 '09 #6
JosAH
11,448 Expert 8TB
@dmjpro
You gave the answer yourself: you didn't deploy on your Windows machine but made NetBeans do all the work for you. Make sure the 'environments' are identical on both computers. btw, don't just put your jars in the /ext directory to make things 'work'; most likely those jars don't belong there. Read this.

kind regards,

Jos
Jan 19 '09 #7
dmjpro
2,476 2GB
What Environments u telling about ?
And i meant to say why it looks from different locations .. ?
Jan 19 '09 #8
JosAH
11,448 Expert 8TB
@dmjpro
By equal 'environments' (mind the quotes) I meant: equal Java JRE versions, equal classpaths, equal available jars etc. I don't know what you mean by 'why it looks from different locations"; please elaborate.

kind regards,

Jos
Jan 19 '09 #9
dmjpro
2,476 2GB
When i try to connect using ...
Expand|Select|Wrap|Line Numbers
  1. DriverManager.registerDriver(new DriverClass());
  2. Connection l_con = DriverManager.getConnection(......);
  3.  
Then it looks from WEB-INF/lib but i use JNDI look up then it looks from class path .. I did mean that ... ;)
Jan 20 '09 #10
r035198x
13,262 8TB
On tomcat the WEB-INF/lib folder is on the path by default.
Jan 20 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Fu Bo Xia | last post: by
reply views Thread by Ravi Tallury | last post: by
2 posts views Thread by Kent Lewandowski | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.