Oortael 10 Beitrag melden gestartet: 22. Mai 2007 Servus Leute, versuche mich gerade auf eine EJB mit Hilfe eines selbstgeschreibenen Clients zu connecten: package helloClient; import java.rmi.RemoteException; import java.util.Hashtable; import javax.ejb.CreateException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import commons.*; public class HelloClient { public static InitialContext createInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); env.put(Context.PROVIDER_URL, "jnp://localhost:1099"); env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); return new InitialContext(env); } public static void main(String[] args) { try { Context iniContxt = createInitialContext(); System.out.println(iniContxt); Context contxt = (Context) iniContxt.lookup("java:comp/env/ejb"); System.out.println(contxt); Object ref = contxt.lookup("helloWorldBean"); System.out.println(ref); HelloHomeIF home = (HelloHomeIF) PortableRemoteObject.narrow(ref, HelloHomeIF.class); System.out.println(home); HelloIF helloIf = home.create(); for (int i = 0; i < 100; i++) { System.out.println("\n*** *** *** ***"); System.out.println("i: "+i); System.out.println(helloIf.getHello()); Fahrzeug fzg = helloIf.search(); System.out.println("Fahrzeug: "+fzg.hashCode()+" Fzg-Nr: "+fzg.getFzgNr()+" Reifen: "+fzg.getWheels()); System.out.println("*** *** *** ***\n"); } } catch (NamingException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } Wenn ich mich nun auf meine Rechner Connecten will, bekomme ich folgende Fehlermeldung: javax.naming.InitialContext@1690726 javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:347) at helloClient.HelloClient.main(HelloClient.java:28) Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385) ... 4 more Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:243) ... 5 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) at java.net.Socket.connect(Socket.java:452) at java.net.Socket.connect(Socket.java:402) at java.net.Socket.<init>(Socket.java:309) at java.net.Socket.<init>(Socket.java:211) at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84) at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77) at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:239) ... 5 more Als IDE verwende ich JbossIDE 1.6 und habe in den BuildPath des Projektes den folgende Libraries eingebunden: jnp-client.jar jboss-common-client.jar j2ee 1.4 Libraries (JBoss-IDE) JRE System Library (jdk) Web Services 1.0 Libraries (JBoss-IDE) Die EJB läuft auf einem JBoss 4.0.5 und ist EJB2.1 konform geschrieben. Die Paketstruktur sieht folgendermaßen aus: Hello |--> src |--> commons |--> Fahrzeug.java |--> HelloBIF.java |--> HelloHomeIF.java |--> HelloIF.java |--> helloBean |--> HelloBean.java |--> helloClient |--> HelloClient.java |--> META-INF |--> ejb-jar.xml |--> jboss.xml Die ejb-jar.xml enthält folgendes: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'> <ejb-jar> <description>Beispiel 1: Stateless session bean </description> <enterprise-beans> <session> <description>Hello</description> <ejb-name>hello</ejb-name> <home>commons.HelloHomeIF</home> <remote>commons.HelloIF</remote> <ejb-class>helloBean.HelloBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> </session> </enterprise-beans> </ejb-jar> Die ejb-jar.xml enthält folgendes: <?xml version='1.0' encoding='UTF-8' ?> <jboss> <enterprise-beans> <entity> <ejb-name>hello</ejb-name> <jndi-name>helloWorldBean</jndi-name> </entity> </enterprise-beans> </jboss> Könnt Ihr mir sagen, was ich falsch mache? Zitieren Diesen Beitrag teilen Link zum Beitrag Auf anderen Seiten teilen
Oortael 10 Beitrag melden geposted: 22. Mai 2007 Hat sich erledigt. Man benötigt nur die jbossall-client.jar. MFG Codefiesler PS: Hier kann dann zu. Zitieren Diesen Beitrag teilen Link zum Beitrag Auf anderen Seiten teilen