javax.naming.NoInitialContextException: Need to specify class name in environment or system property - Websphere
This is a discussion on javax.naming.NoInitialContextException: Need to specify class name in environment or system property - Websphere ; I am new to this forum.
I have a question on how to set up and refer Datasources using JNDI.
Database: informix
WSAD:5.1
WAS:5.0
here is the client code:
import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public static void main(String[] args)
...
-
javax.naming.NoInitialContextException: Need to specify class name in environment or system property
I am new to this forum.
I have a question on how to set up and refer Datasources using JNDI.
Database: informix
WSAD:5.1
WAS:5.0
here is the client code:
import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public static void main(String[] args)
{
String dsName = "jdbc/ops";
Connection con = null;
try
{
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dsName);
System.out.println("pooled-connection");
con = ds.getConnection();
}
catch (Exception ne) {
// Connection factory cannot be looked up.
System.out.println("fail to connect");
}
}
This I created a J2EE client application and added it in EAR module.
I created a server with default test server. In server setting I selected datasource and add informix driver to JDBC provider list and defined the datasource for JDBC driver.
I start the server and when server is ready.
I go to client launcher to do debug.
I get the above exception.
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
Are you running it by selecting "Debug As... > WebSphere v5 Application
Client"?
Wayne
"feroz_m" wrote in message
news:1178060103.1081201058232.JavaMail.wasadmin@sw g3ws006...
> I am new to this forum.
> I have a question on how to set up and refer Datasources using JNDI.
>
> Database: informix
> WSAD:5.1
> WAS:5.0
>
> here is the client code:
>
> import java.sql.Connection;
>
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
>
> public static void main(String[] args)
> {
> String dsName = "jdbc/ops";
> Connection con = null;
> try
> {
> InitialContext ic = new InitialContext();
> DataSource ds = (DataSource) ic.lookup(dsName);
> System.out.println("pooled-connection");
> con = ds.getConnection();
> }
>
> catch (Exception ne) {
> // Connection factory cannot be looked up.
> System.out.println("fail to connect");
> }
> }
>
> This I created a J2EE client application and added it in EAR module.
> I created a server with default test server. In server setting I selected
datasource and add informix driver to JDBC provider list and defined the
datasource for JDBC driver.
> I start the server and when server is ready.
> I go to client launcher to do debug.
> I get the above exception.
>
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
WAS is running w/o debug mode.
client app is rumnning in debug mode.
I am trying to do connection pooling. I was thinking that If I sepcify the datasource, then I can do pooling.
thanks
> Are you running it by selecting "Debug As... >
> WebSphere v5 Application
> Client"?
>
> Wayne
>
> "feroz_m" wrote in message
> news:1178060103.1081201058232.JavaMail.wasadmin@sw g3ws
> 06...
> > I am new to this forum.
> > I have a question on how to set up and refer
> Datasources using JNDI.
> >
> > Database: informix
> > WSAD:5.1
> > WAS:5.0
> >
> > here is the client code:
> >
> > import java.sql.Connection;
> >
> > import javax.naming.InitialContext;
> > import javax.sql.DataSource;
> >
> > public static void main(String[] args)
> > {
> > String dsName = "jdbc/ops";
> > Connection con = null;
> > try
> > {
> > InitialContext ic = new InitialContext();
> > DataSource ds = (DataSource) ic.lookup(dsName);
> > System.out.println("pooled-connection");
> > con = ds.getConnection();
> > }
> >
> > catch (Exception ne) {
> > // Connection factory cannot be looked up.
> > System.out.println("fail to connect");
> > }
> > }
> >
> > This I created a J2EE client application and added
> it in EAR module.
> > I created a server with default test server. In
> server setting I selected
> datasource and add informix driver to JDBC provider
> list and defined the
> datasource for JDBC driver.
> > I start the server and when server is ready.
> > I go to client launcher to do debug.
> > I get the above exception.
> >
>
>
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
I should have been more explicit. The error you indicate makes me think that
you're not running your client code in the application client container. You
need to run in the application client container to access JNDI.
Are you running the client as a J2EE application client?
Wayne
"feroz_m" wrote in message
news:1390586940.1081255555495.JavaMail.wasadmin@sw g3ws006...
> WAS is running w/o debug mode.
> client app is rumnning in debug mode.
> I am trying to do connection pooling. I was thinking that If I sepcify the
datasource, then I can do pooling.
> thanks
> > Are you running it by selecting "Debug As... >
> > WebSphere v5 Application
> > Client"?
> >
> > Wayne
> >
> > "feroz_m" wrote in message
> > news:1178060103.1081201058232.JavaMail.wasadmin@sw g3ws
> > 06...
> > > I am new to this forum.
> > > I have a question on how to set up and refer
> > Datasources using JNDI.
> > >
> > > Database: informix
> > > WSAD:5.1
> > > WAS:5.0
> > >
> > > here is the client code:
> > >
> > > import java.sql.Connection;
> > >
> > > import javax.naming.InitialContext;
> > > import javax.sql.DataSource;
> > >
> > > public static void main(String[] args)
> > > {
> > > String dsName = "jdbc/ops";
> > > Connection con = null;
> > > try
> > > {
> > > InitialContext ic = new InitialContext();
> > > DataSource ds = (DataSource) ic.lookup(dsName);
> > > System.out.println("pooled-connection");
> > > con = ds.getConnection();
> > > }
> > >
> > > catch (Exception ne) {
> > > // Connection factory cannot be looked up.
> > > System.out.println("fail to connect");
> > > }
> > > }
> > >
> > > This I created a J2EE client application and added
> > it in EAR module.
> > > I created a server with default test server. In
> > server setting I selected
> > datasource and add informix driver to JDBC provider
> > list and defined the
> > datasource for JDBC driver.
> > > I start the server and when server is ready.
> > > I go to client launcher to do debug.
> > > I get the above exception.
> > >
> >
> >
>
>
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
in your wsad, run the application as "Websphere v XX Application Client".
You can find it under "Run -> Run As -> Websphere v XX Application Client"
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
In fact your are correct. But right know I get
>>>>>>>Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
<<<<<<<<<<<<<<<<<<<<<
import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public static void main(String[] args)
{
String dsName = "jdbc/ops";
Connection con = null;
try
{
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dsName);
System.out.println("pooled-connection");
con = ds.getConnection();
}
catch (Exception ne) {
// Connection factory cannot be looked up.
System.out.println("fail to connect");
}
}
1.Select J2EE project and created J2EE 1.3 EAR Project with application Client project, added to EAR Module.
2.In the J2EE Hierarchy view, right-click the desired application client module and select Open With --> Deployment Descriptor Editor from the context menu.
On the References page of the editor, click Add. The Add Reference wizard appears.
3.On the References page of the editor, click Add. The Add Reference wizard appears.
4.Select Resource reference as the reference type, and click Next.
5.In the Name field, specify the name of the resource reference "jdbc/ops".
6.In the Type field, enter the expected type of the resource manager connection factory and selected :javax.sql.DataSource
In project navigator view I added a class as describe earlier.
In server prospective I created a test server with server type of test envirnment.
For this server In DataSource I created server setting for Informix datasource.
I run this WAS server. When the server is open.
Then I click websphere V5 Application client and debug it mode. It does gives me
##################################### these error when I run Client application in debug mode ################
WSCL0100E: Exception received: com.ibm.etools.archive.exception.ResourceLoadExcep tion: IWAE0007E Could not load resource "META-INF/client-resource.xmi" in archive "DemoApplicationClient.jar"
Stack trace of nested exception:
Wrapped exception
java.io.FileNotFoundException: D:\TalkAmerica\workspace\DemoApplicationClient\app ClientModule\META-INF\client-resource.xmi (The system cannot find the file specified.
)
at java.lang.Throwable.(Throwable.java)
at java.lang.Throwable.(Throwable.java)
at java.io.FileNotFoundException.(FileNotFoundException.java:76)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:78)
at com.ibm.etools.archive.impl.DirectoryLoadStrategyI mpl.getInputStream(DirectoryLoadStrategyImpl.java: 117)
at com.ibm.etools.commonarchive.impl.ContainerImpl.pr imGetInputStream(ContainerImpl.java:258)
at com.ibm.etools.commonarchive.impl.ContainerImpl.ge tInputStream(ContainerImpl.java:237)
at com.ibm.etools.archive.impl.ArchiveURIConverterImp l.createInputStream(ArchiveURIConverterImpl.java:5 3)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.l oad(ResourceImpl.java:752)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.demandLoad(ResourceSetImpl.java:220)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.getResource(ResourceSetImpl.java:286)
at com.ibm.etools.archive.impl.LoadStrategyImpl.getMo fResource(LoadStrategyImpl.java:311)
at com.ibm.etools.commonarchive.impl.ArchiveImpl.getM ofResource(ArchiveImpl.java:764)
at com.ibm.ws.client.applicationclient.ClientContaine rResourceRepositoryImpl.loadResourceFile(ClientCon tainerResourceRepositoryImpl.java:516)
at com.ibm.ws.client.applicationclient.ApplicationCli entMetaData.getResourceConfigInfo(ApplicationClien tMetaData.java:705)
at com.ibm.ws.client.applicationclient.ClientContaine r.addResourceEntries(ClientContainer.java:380)
at com.ibm.ws.client.applicationclient.ClientContaine r.init(ClientContainer.java:168)
at com.ibm.websphere.client.applicationclient.launchC lient.createContainerAndLaunchApp(launchClient.jav a:590)
at com.ibm.websphere.client.applicationclient.launchC lient.main(launchClient.java:420)
at java.lang.reflect.AccessibleObject.invokeImpl(Nati ve Method)
at java.lang.reflect.AccessibleObject.invokeV(Accessi bleObject.java:199)
at java.lang.reflect.Method.invoke(Method.java:252)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:94)
Wrapped by
org.eclipse.emf.common.util.WrappedException: D:\TalkAmerica\workspace\DemoApplicationClient\app ClientModule\META-INF\client-resource.xmi (The system cannot find the file specified.
)
at java.lang.Throwable.(Throwable.java)
at java.lang.Throwable.(Throwable.java)
at org.eclipse.emf.common.util.WrappedException.(WrappedException.java:40)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.getResource(ResourceSetImpl.java:294)
at com.ibm.etools.archive.impl.LoadStrategyImpl.getMo fResource(LoadStrategyImpl.java:311)
at com.ibm.etools.commonarchive.impl.ArchiveImpl.getM ofResource(ArchiveImpl.java:764)
at com.ibm.ws.client.applicationclient.ClientContaine rResourceRepositoryImpl.loadResourceFile(ClientCon tainerResourceRepositoryImpl.java:516)
at com.ibm.ws.client.applicationclient.ApplicationCli entMetaData.getResourceConfigInfo(ApplicationClien tMetaData.java:705)
at com.ibm.ws.client.applicationclient.ClientContaine r.addResourceEntries(ClientContainer.java:380)
at com.ibm.ws.client.applicationclient.ClientContaine r.init(ClientContainer.java:168)
at com.ibm.websphere.client.applicationclient.launchC lient.createContainerAndLaunchApp(launchClient.jav a:590)
at com.ibm.websphere.client.applicationclient.launchC lient.main(launchClient.java:420)
at java.lang.reflect.AccessibleObject.invokeImpl(Nati ve Method)
at java.lang.reflect.AccessibleObject.invokeV(Accessi bleObject.java:199)
at java.lang.reflect.Method.invoke(Method.java:252)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:94)
WSCL0205W: The incorrect class loader was used to load class DemoClient
##################################### End ################################################## #################
>>>>> this is the error I am getting
Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object.
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
Right, this is expected. When you get the data source from JNDI, you're
getting a copy of the data source, it doesn't live on the server. The
problem is that you can get the data source, but the data source cannot work
on the client with all the drivers and stuff that it needs to work. Setting
this is up is a little yucky (there's no way to do this in WebSphere
Studio). But before I get to that...
Do you really need to use a data source in your application client? Data
sources are intended for systems that are servicing hundreds of concurrent
users. Most application clients tend to have a single client. If this is the
case, then DriverManager will probably do the job for you. If you're only
going to use one connection, why bother with a connection pool?
Remember that the the datasource is copied from the server, so each instance
of your application client gets their own copy. There will be no pooling
between application client instances. If this is what you need, then you'll
have to look at other options.
Assuming that you really do need to use the data source, here's what you
need to do:
1) Take a deep cleansing breath
2) Export your enterprise application (and application client) into an EAR
file.
3) Start up the ACRCT tool ("clientConfig.bat" in Windows)
4) Open your EAR file
5) Configure a "Data Source Provider" (classpath points to your database's
JAR file "db2java.zip" for example; and implementation class
"COM.ibm.db2.jdbc.app.DB2Driver"
6) Configure a "Data Source" for your provider that provides the particular
information about the database you want to access (basically repeat
everything that you specified when you created the datasource on the
server).
7) Save the changes
8) Open the EAR file and navigate into your application client's META-INF
directory to find the client-resource.xmi file. Copy this file into the
META-INF directory of the application client in WebSphere Studio.
It should work. Unfortunately, I don't have a workstation configured to
actually test this (I'm in the middle of some major repairs), so I'm doing
this from memory. I may have missed a step.
I'm curious to know why you think you need to use a data source....
Hope this helps,
Wayne
"feroz_m" wrote in message
news:1406331913.1081285237330.JavaMail.wasadmin@sw g3ws006...
> In fact your are correct. But right know I get
> >>>>>>>Exception occurred while the JNDI NamingManager was processing a
javax.naming.Reference object.
> <<<<<<<<<<<<<<<<<<<<<
> import java.sql.Connection;
>
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
>
> public static void main(String[] args)
> {
> String dsName = "jdbc/ops";
> Connection con = null;
> try
> {
> InitialContext ic = new InitialContext();
> DataSource ds = (DataSource) ic.lookup(dsName);
> System.out.println("pooled-connection");
> con = ds.getConnection();
> }
>
> catch (Exception ne) {
> // Connection factory cannot be looked up.
> System.out.println("fail to connect");
> }
> }
>
>
> 1.Select J2EE project and created J2EE 1.3 EAR Project with application
Client project, added to EAR Module.
> 2.In the J2EE Hierarchy view, right-click the desired application client
module and select Open With --> Deployment Descriptor Editor from the
context menu.
> On the References page of the editor, click Add. The Add Reference wizard
appears.
> 3.On the References page of the editor, click Add. The Add Reference
wizard appears.
> 4.Select Resource reference as the reference type, and click Next.
> 5.In the Name field, specify the name of the resource reference
"jdbc/ops".
> 6.In the Type field, enter the expected type of the resource manager
connection factory and selected :javax.sql.DataSource
>
> In project navigator view I added a class as describe earlier.
> In server prospective I created a test server with server type of test
envirnment.
> For this server In DataSource I created server setting for Informix
datasource.
> I run this WAS server. When the server is open.
> Then I click websphere V5 Application client and debug it mode. It does
gives me
> ##################################### these error when I run Client
application in debug mode ################
> WSCL0100E: Exception received:
com.ibm.etools.archive.exception.ResourceLoadExcep tion: IWAE0007E Could not
load resource "META-INF/client-resource.xmi" in archive
"DemoApplicationClient.jar"
> Stack trace of nested exception:
> Wrapped exception
> java.io.FileNotFoundException:
D:\TalkAmerica\workspace\DemoApplicationClient\app ClientModule\META-INF\clie
nt-resource.xmi (The system cannot find the file specified.
> )
> at java.lang.Throwable.(Throwable.java)
> at java.lang.Throwable.(Throwable.java)
> at java.io.FileNotFoundException.(FileNotFoundException.java:76)
> at java.io.FileInputStream.open(Native Method)
> at java.io.FileInputStream.(FileInputStream.java:78)
> at
com.ibm.etools.archive.impl.DirectoryLoadStrategyI mpl.getInputStream(Directo
ryLoadStrategyImpl.java:117)
> at
com.ibm.etools.commonarchive.impl.ContainerImpl.pr imGetInputStream(Container
Impl.java:258)
> at
com.ibm.etools.commonarchive.impl.ContainerImpl.ge tInputStream(ContainerImpl
..java:237)
> at
com.ibm.etools.archive.impl.ArchiveURIConverterImp l.createInputStream(Archiv
eURIConverterImpl.java:53)
> at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.l oad(ResourceImpl.java:752)
> at
org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.demandLoad(ResourceSetIm
pl.java:220)
> at
org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.getResource(ResourceSetI
mpl.java:286)
> at
com.ibm.etools.archive.impl.LoadStrategyImpl.getMo fResource(LoadStrategyImpl
..java:311)
> at
com.ibm.etools.commonarchive.impl.ArchiveImpl.getM ofResource(ArchiveImpl.jav
a:764)
> at
com.ibm.ws.client.applicationclient.ClientContaine rResourceRepositoryImpl.lo
adResourceFile(ClientContainerResourceRepositoryIm pl.java:516)
> at
com.ibm.ws.client.applicationclient.ApplicationCli entMetaData.getResourceCon
figInfo(ApplicationClientMetaData.java:705)
> at
com.ibm.ws.client.applicationclient.ClientContaine r.addResourceEntries(Clien
tContainer.java:380)
> at
com.ibm.ws.client.applicationclient.ClientContaine r.init(ClientContainer.jav
a:168)
> at
com.ibm.websphere.client.applicationclient.launchC lient.createContainerAndLa
unchApp(launchClient.java:590)
> at
com.ibm.websphere.client.applicationclient.launchC lient.main(launchClient.ja
va:420)
> at java.lang.reflect.AccessibleObject.invokeImpl(Nati ve Method)
> at java.lang.reflect.AccessibleObject.invokeV(Accessi bleObject.java:199)
> at java.lang.reflect.Method.invoke(Method.java:252)
> at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:94)
> Wrapped by
> org.eclipse.emf.common.util.WrappedException:
D:\TalkAmerica\workspace\DemoApplicationClient\app ClientModule\META-INF\clie
nt-resource.xmi (The system cannot find the file specified.
> )
> at java.lang.Throwable.(Throwable.java)
> at java.lang.Throwable.(Throwable.java)
> at
org.eclipse.emf.common.util.WrappedException.(WrappedException.java:40
)
> at
org.eclipse.emf.ecore.resource.impl.ResourceSetImp l.getResource(ResourceSetI
mpl.java:294)
> at
com.ibm.etools.archive.impl.LoadStrategyImpl.getMo fResource(LoadStrategyImpl
..java:311)
> at
com.ibm.etools.commonarchive.impl.ArchiveImpl.getM ofResource(ArchiveImpl.jav
a:764)
> at
com.ibm.ws.client.applicationclient.ClientContaine rResourceRepositoryImpl.lo
adResourceFile(ClientContainerResourceRepositoryIm pl.java:516)
> at
com.ibm.ws.client.applicationclient.ApplicationCli entMetaData.getResourceCon
figInfo(ApplicationClientMetaData.java:705)
> at
com.ibm.ws.client.applicationclient.ClientContaine r.addResourceEntries(Clien
tContainer.java:380)
> at
com.ibm.ws.client.applicationclient.ClientContaine r.init(ClientContainer.jav
a:168)
> at
com.ibm.websphere.client.applicationclient.launchC lient.createContainerAndLa
unchApp(launchClient.java:590)
> at
com.ibm.websphere.client.applicationclient.launchC lient.main(launchClient.ja
va:420)
> at java.lang.reflect.AccessibleObject.invokeImpl(Nati ve Method)
> at java.lang.reflect.AccessibleObject.invokeV(Accessi bleObject.java:199)
> at java.lang.reflect.Method.invoke(Method.java:252)
> at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:94)
>
> WSCL0205W: The incorrect class loader was used to load class DemoClient
> ##################################### End
################################################## #################
> >>>>> this is the error I am getting
> Exception occurred while the JNDI NamingManager was processing a
javax.naming.Reference object.
>
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
thanks wayne for your help.
yes we need datasource as there will be more than 200 users
I am testing my framework which give me pool connection. for this reason I am using client application.
I perform the step #7 and save the changes.
for step#8 I could not find any *.xmi file. Is this one generated by ACRCT tool.
you help will appericate.
How to create that file ???
Feroz
-
Re: javax.naming.NoInitialContextException: Need to specify class name in environment or system property
Just be be clear: are you saying that a single instance of your client will
have 200 users?
The client-resources.xmi file should be in the application client JAR inside
the EAR.
Wayne
"feroz_m" wrote in message
news:1624399115.1081374200447.JavaMail.wasadmin@sw g3ws006...
> thanks wayne for your help.
> yes we need datasource as there will be more than 200 users
> I am testing my framework which give me pool connection. for this reason I
am using client application.
>
> I perform the step #7 and save the changes.
> for step#8 I could not find any *.xmi file. Is this one generated by ACRCT
tool.
> you help will appericate.
> How to create that file ???
> Feroz