Skip to Content
0
Former Member
Sep 27, 2006 at 06:29 AM

Connecting to Netweaver Portal from Stand Alone Java application

78 Views

Hi all,

I have a SAP Netweaver 2004s server running.

There are already some examples provided in the "J2EE Example" section.

There is one example regarding the "Hello.ear" bean.

I can access this bean form the hello.jsp provided along with the example.

Now i want to access the same form a remote Java Command Line application .

The code is as follows:

import javax.naming.*;

import java.util.*;

import java.util.Hashtable;

import java.rmi.RemoteException;

import com.sap.engine.examples.ejb.hello.*;

public class HelloClient

{

public static void main(String[] args) throws Exception{

Hello remotebean=null;

Properties p = new Properties();

p.put(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl");

p.put(Context.PROVIDER_URL, "137.72.243.90:50104");

p.put(Context.SECURITY_PRINCIPAL, "Administrator");

p.put(Context.SECURITY_CREDENTIALS, "password1");

Context ctx = (Context) new InitialContext(p);

Object objRef = ctx.lookup("HelloStatelessBean");

HelloHome ejbHome = (HelloHome)objRef ;

remotebean = ejbHome.create();

}

}

I could compile the code

but when i try run it i get the following exception

E:\>set classpath=%classpath%;E:\SAPEP\demo\NW2004s\ejb20.jar;E:\SAPEP\demo\NW

04s\HelloEJB.jar;E:\SAPEP\demo\NW2004s\Hello_client.jar;

E:\>cd E:\SAPEP\demo\NW2004s

E:\SAPEP\demo\NW2004s>javac HelloClient.java

E:\SAPEP\demo\NW2004s>java HelloClient

Exception in thread "main" javax.naming.NoInitialContextException: Cannot inst

tiate class: com.sap.engine.services.jndi.InitialContextFactoryImpl [Root exce

ion is java.lang.ClassNotFoundException: com.sap.engine.services.jndi.InitialC

textFactoryImpl]

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java

52)

at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:2

)

at javax.naming.InitialContext.init(InitialContext.java:219)

at javax.naming.InitialContext.<init>(InitialContext.java:195)

at HelloClient.main(HelloClient.java:44)

Caused by: java.lang.ClassNotFoundException: com.sap.engine.services.jndi.Init

lContextFactoryImpl

at java.net.URLClassLoader$1.run(URLClassLoader.java:199)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:219)

at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.j

a:42)

at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java

49)

... 4 more

Why am i getting this exception.

Can you please help me in this.