1 Reply Latest reply on May 27, 2005 4:12 PM by Kun Men

    Need help on deploy my EJB-client to JBoss 4.0.2

    Kun Men Newbie

      Would anybody please help me on my issue? thanks your advice in advance! I use Jboss4.0.2, and the os is Win2k.
      Followed the 'duke bank' example in Startguide, I write a simple example. which only has one EJB and a client. By 'ant -f jboss-build.xml deploy', I have deployed it to the Jboss 4.0.2 (default server), and it is said it has been success deployed and started. However, when I run the client by 'ant -f jboss-build.xml run-client', I got such errors:

      [java] Caught an unexpected exception!
      [java] java.lang.SecurityException: Unable to locate a login configuration
      [java] at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java
      :97)
      [java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
      Method)
      [java] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeC
      onstructorAccessorImpl.java:39)
      [java] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Del
      egatingConstructorAccessorImpl.java:27)
      [java] at java.lang.reflect.Constructor.newInstance(Constructor.java:27
      4)
      [java] at java.lang.Class.newInstance0(Class.java:308)
      [java] at java.lang.Class.newInstance(Class.java:261)
      [java] at javax.security.auth.login.Configuration$3.run(Configuration.j
      ava:221)
      [java] at java.security.AccessController.doPrivileged(Native Method)
      [java] at javax.security.auth.login.Configuration.getConfiguration(Conf
      iguration.java:215)
      [java] at javax.security.auth.login.LoginContext$1.run(LoginContext.jav
      a:170)
      [java] at java.security.AccessController.doPrivileged(Native Method)
      [java] at javax.security.auth.login.LoginContext.init(LoginContext.java
      :167)
      [java] at javax.security.auth.login.LoginContext.<init>(LoginContext.ja
      va:404)
      [java] at org.jboss.security.jndi.LoginInitialContextFactory.getInitial
      Context(LoginInitialContextFactory.java:69)
      [java] at javax.naming.spi.NamingManager.getInitialContext(NamingManage
      r.java:662)
      [java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.
      java:243)
      [java] at javax.naming.InitialContext.init(InitialContext.java:219)
      [java] at javax.naming.InitialContext.<init>(InitialContext.java:175)
      [java] at GoldClient.main(GoldClient.java:14)
      [java] Caused by: java.io.IOException: Unable to locate a login configurati
      on
      [java] at com.sun.security.auth.login.ConfigFile.init(ConfigFile.java:2
      06)
      [java] at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java
      :95)
      [java] ... 19 more


      I don't know what is wrong with it, actually I have deployed it by 'sun deploytool' to the sun j2ee sdk 1.4 default server, and everything work perfect. So I guess the problem is caused by the JNDI or the deployment descriptor of my client. Here I give all the info:

      jboss-build.xml:

      <project name="jboss-MiningGold" default="all" basedir=".">
       <property file="./jboss-build.properties"/>
      
       <property name="lib.dir" value="../libs"/>
       <property name="src.dir" value="${basedir}/src"/>
       <property name="build.dir" value="${basedir}/build"/>
      
      
      
       <!-- The classpath for running the client -->
       <path id="client.classpath">
       <pathelement location="${build.dir}"/>
       <fileset dir="${jboss.home}/client">
       <include name="**/*.jar"/>
       </fileset>
       </path>
      
       <!-- The build classpath -->
       <path id="axis.classpath">
       <pathelement location="${build.dir}"/>
       <fileset dir="/Users/orb/Desktop/axis-1_1/lib">
       <include name="*.jar"/>
       </fileset>
       <fileset dir="${jboss.server}/lib/">
       <include name="javax.servlet*.jar"/>
       </fileset>
       </path>
      
      
       <!-- The build classpath -->
       <path id="build.classpath">
       <path refid="client.classpath"/>
       <fileset dir="${jboss.server}/lib/">
       <include name="javax.servlet*.jar"/>
       </fileset>
       <!-- for java2wsdl -->
       <fileset dir="${jboss.server}/deploy/jboss-ws4ee.sar/">
       <include name="*.jar"/>
       </fileset>
       </path>
      
       <!-- =================================================================== -->
       <!-- Initialises the build. -->
       <!-- =================================================================== -->
       <target name="prepare">
       <mkdir dir="${build.dir}"/>
       </target>
      
       <!-- ================================================================ -->
       <!-- Compiles the source code -->
       <!-- ================================================================ -->
       <target name="compile" depends="prepare">
       <javac destdir="${build.dir}" classpathref="build.classpath"
       debug="on">
       <src path="${src.dir}"/>
       </javac>
       </target>
      
       <target name="package-ejb" depends="compile">
       <mkdir dir="jar" />
       <delete file="jar/gold-ejb.jar"/>
      
       <jar jarfile="jar/gold-ejb.jar">
       <metainf dir="dd/ejb" includes="**/*.xml" />
      
       <fileset dir="${build.dir}">
       <include name="gold/**"/>
       </fileset>
       </jar>
       </target>
      
       <target name="package-client" depends="compile">
       <mkdir dir="jar" />
       <delete file="jar/app-client.jar"/>
      
       <jar jarfile="jar/app-client.jar">
       <metainf dir="dd/client" includes="*.xml"/>
       <fileset dir="${build.dir}">
       <include name="GoldClient.class"/>
       <include name="gold/Gold.class"/>
       <include name="gold/GoldHome.class"/>
       </fileset>
       <fileset dir="dd/client">
       <include name="jndi.properties"/>
       </fileset>
       </jar>
       </target>
      
       <!-- Creates an ear file containing the ejb jars and the web client war. -->
       <target name="assemble-app">
       <delete file="jar/MiningGold.ear"/>
       <ear destfile="jar/MiningGold.ear" appxml="dd/application.xml">
       <fileset dir="jar" includes="*-ejb.jar,app-client.jar"/>
       </ear>
       </target>
      
       <!-- Deploys the EAR file by copying it to the JBoss deploy directory. -->
       <target name="deploy" depends="assemble-app">
       <copy file="jar/MiningGold.ear" todir="${jboss.server}/deploy"/>
       </target>
      
       <!-- Run the standalone client -->
       <target name="run-client">
       <echo>${java.class.path}</echo>
       <java classname="GoldClient" fork="yes">
       <classpath>
       <pathelement path="jar/app-client.jar"/>
       <path refid="client.classpath"/>
       <pathelement path="${java.class.path}"/>
       </classpath>
       </java>
       </target>
      
      
       <target name="clean">
       <delete dir="${build.dir}" />
       <mkdir dir="${build.dir}" />
      
       </target>
      
      
       <target name="all" depends="compile,package-ejb,package-client,assemble-app,deploy" />
      
      </project>
      

      EJB deployment desriptor:
      ejb-jar.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar >
      
       <description><![CDATA[No Description.]]></description>
       <display-name>Generated by XDoclet</display-name>
      
       <enterprise-beans>
      
       <!-- Session Beans -->
       <session >
       <description><![CDATA[Description for Gold]]></description>
       <display-name>Name for Gold</display-name>
      
       <ejb-name>Gold</ejb-name>
      
       <home>gold.GoldHome</home>
       <remote>gold.Gold</remote>
       <ejb-class>gold.GoldBean</ejb-class>
       <session-type>Stateful</session-type>
       <transaction-type>Container</transaction-type>
      
       </session>
      
      
       </enterprise-beans>
      
       <assembly-descriptor >
       </assembly-descriptor>
      
      </ejb-jar>
      

      jboss.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
      
      <jboss>
      
       <enterprise-beans>
      
       <session>
       <ejb-name>Gold</ejb-name>
       <jndi-name>ejb/Gold</jndi-name>
      
       <method-attributes>
       </method-attributes>
       </session>
      
       </enterprise-beans>
      
       <resource-managers>
       </resource-managers>
      
      </jboss>
      

      For client:
      jboss-client.xml:
      <jboss-client>
       <jndi-name>Gold-client</jndi-name>
      
       <ejb-ref>
       <ejb-ref-name>ejb/SimpleGold</ejb-ref-name>
       <jndi-name>ejb/Gold</jndi-name>
       </ejb-ref>
      
      </jboss-client>
      

      application-client.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <!DOCTYPE application-client PUBLIC
       '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN'
       'http://java.sun.com/dtd/application-client_1_3.dtd'>
      <application-client>
       <display-name>GoldClient</display-name>
      
       <ejb-ref>
       <ejb-ref-name>ejb/SimpleGold</ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <home>GoldHome</home>
       <remote>Gold</remote>
       </ejb-ref>
      </application-client>
      


      jndi.properties
      java.naming.factory.initial=org.jboss.security.jndi.LoginInitialContextFactory
      #org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=jnp://localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming.client
      java.naming.security.principal=200
      java.naming.security.credentials=j2ee
      java.naming.security.protocol=client-login
      j2ee.clientName=Gold-client
      


      *******************************************************************************************
      The java files:

      GoldBean.java:
      package gold;
      
      import java.rmi.RemoteException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import java.math.*;
      
      
      public class GoldBean implements SessionBean {
       BigDecimal Increase_Rate = new BigDecimal("1.0000");
      
       public GoldBean() {
       }
      
       public BigDecimal MiningGold(BigDecimal dollars, String userName) {
       BigDecimal result = dollars.add(Increase_Rate);
       System.out.print(userName + " has earned: ");
       System.out.println(result);
       return result;
       }
      
       public void ejbCreate() {
       }
      
       public void ejbRemove() {
       }
      
       public void ejbActivate() {
       }
      
       public void ejbPassivate() {
       }
      
       public void setSessionContext(SessionContext sc) {
       }
      }

      Gold.java:
      package gold;
      
      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;
      import java.math.*;
      
      public interface Gold extends EJBObject {
       public BigDecimal MiningGold(BigDecimal dollars, String userName) throws RemoteException;
      }

      GoldHome.java:
      package gold;
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;
      
      
      public interface GoldHome extends EJBHome {
       Gold create() throws RemoteException, CreateException;
      }

      GoldClient.java:
      import gold.Gold;
      import gold.GoldHome;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      import java.math.BigDecimal;
      import java.io.*;
      
      
      public class GoldClient {
       public static void main(String[] args) {
       try {
       Context initial = new InitialContext();
       Context myEnv = (Context) initial.lookup("java:comp/env");
       Object objref = myEnv.lookup("ejb/SimpleGold");
      
       GoldHome home =
       (GoldHome) PortableRemoteObject.narrow(objref,
       GoldHome.class);
      
       Gold FindGold = home.create();
      
       BigDecimal param = new BigDecimal("0.00");
       BigDecimal amount = new BigDecimal("0.00");
      
       System.out.print("Enter the name of your company: ");
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       String userName = null;
       try {
       userName = br.readLine();
       } catch (IOException ioe) {
       System.out.println("IO error trying to read your name!");
       System.exit(1);
       }
      
      
       for (int i=0; i<5000000; i++) {
       if (i%200==0){
       amount = FindGold.MiningGold(param, userName);
       param = amount;
       System.out.print(userName + " has earned: ");
       System.out.println(amount);
       }
       }
      
      
       System.exit(0);
       } catch (Exception ex) {
       System.err.println("Caught an unexpected exception!");
       ex.printStackTrace();
       }
       }
      }