users@glassfish.java.net

Glassfish: Unable to inject _at_Resource into ApplicationClient using ACC

From: <glassfish_at_javadesktop.org>
Date: Wed, 24 Jun 2009 11:00:19 PDT

Hi,

I am trying to inject a @Resource into Application Client.

Here is my ApplicationClient:

   1. package arun.di;
   2. import javax.naming.*;
   3. import java.util.*;
   4. import javax.ejb.*;
   5. import javax.annotation.Resource;
   6. import javax.sql.DataSource;
   7. import java.sql.*;
   8.
   9. public class ResourceInjectionDemo {
  10.
  11. @Resource(name="jdbc/abcd")
  12. private static DataSource ds;
  13. public static void main(String args[]) throws
Exception{
  14.
  15. Connection con = ds.getConnection();
  16.
  17. System.out.println("Connection established:" +
con.isValid(10));
  18.
  19. }
  20.
  21. }

I am using GlassFish application Server and Oracle 10g database.

Step 1.
-------
I created a connection pool with (just for testing) [ on
Glassfish admin console http://localhost:4848] :

Name: abc
Datasource Classname: oracle.jdbc.pool.OracleDataSource
Resource Type: javax.sql.DataSource
URL : jdbc:oracle:thin:@localhost:1521:myservicename
user name: scott
password : tiger

Ping was successful.

Step 2
--------
I create JDBC > JDBC Resource.

JNDI Name: jdbc/abcd
Pool Name : abc (selected 'abc' from dropdown)


I have this CLASSPATH = javaee.jar; [ provided by Glassfish ]
appserv-rt.jar; [ provided by Glassfish ]
[b]ojdbc14.jar[/b]; [provided by oracle ]

MANIFEST.MF has correct entry :
-------------------------------------
Main-Class: arun.di.ResourceInjectionDemo

I packaged my application client into c.jar. [c for client]

This is how I am invoking my application client:

C:\arun\ejb3practice\DI\ApplicationClient>appclient -client
c.jar

    Jun 24, 2009 12:26:11 AM
com.sun.gjc.common.DataSourceObjectBuilder getDataSourc
    eObject
    SEVERE: RAR5099 : Wrong class name or classpath for
Datasource Object
    java.lang.ClassNotFoundException:
oracle.jdbc.pool.OracleDataSource
    at
com.sun.enterprise.loader.EJBClassLoader.findClassData(EJBClassLoader
    .java:738)
    at
com.sun.enterprise.loader.EJBClassLoader.findClass(EJBClassLoader.jav
    a:628)

    ...........
    ...........

    WARNING: RAR5038:Unexpected exception while creating
resource for pool abc. Exce
    ption : Class name is wrong or classpath is not set for
: oracle.jdbc.pool.Oracl
    eDataSource
    Jun 24, 2009 12:26:11 AM
com.sun.enterprise.connectors.ConnectionManagerImpl int
    ernalGetConnection
    WARNING: RAR5117 : Failed to obtain/create connection
from connection pool [ abc
    ]. Reason : Class name is wrong or classpath is not set
for : oracle.jdbc.pool.
    OracleDataSource
    Jun 24, 2009 12:26:11 AM com.sun.gjc.spi.base.DataSource
getConnection
    WARNING: RAR5114 : Error allocating connection : [Error
in allocating a connecti
    on. Cause: Class name is wrong or classpath is not set
for : oracle.jdbc.pool.Or
    acleDataSource]
    Jun 24, 2009 12:26:11 AM
com.sun.enterprise.appclient.MainWithModuleSupport <ini
    t>
    WARNING: ACC003: Application threw an exception.
    java.sql.SQLException: Error in allocating a connection.
Cause: Class name is wr
    ong or classpath is not set for :
oracle.jdbc.pool.OracleDataSource
    at
com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:115)
    at
arun.di.ResourceInjectionDemo.main(ResourceInjectionDemo.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
    ....


C:\arun\ejb3practice\DI\ApplicationClient>


I dont know why it is saying Caused by:
java.sql.SQLException: Error in allocating a connection.
Cause: Class
name is wrong or classpath is not set for :
oracle.jdbc.pool.OracleDataSource.

I have ojdbc14.jar in my CLASSPATH.
C:\arun\ejb3practice\DI\ApplicationClient>set CLASSPATH
CLASSPATH=;C:\arun\softwares\Java\Java
Kingdom\GlassFish\glassfish\lib\javaee.ja
r;C:\arun\softwares\Java\Java
Kingdom\GlassFish\glassfish\lib\appserv-rt.jar;;C:
\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar;



NOTE: Also, before starting the domain1 of Glassfish, I have
copied ojdbc14.jar to glassfish\domains\domain1\lib\ext dir.

Please tell me where I am wrong.
[Message sent by forum member 'arunkumark007' (arunkumark007)]

http://forums.java.net/jive/thread.jspa?messageID=352772