14 Replies Latest reply on Mar 19, 2009 5:30 PM by Peter Johnson

    A true newbie -- Please help!

    Rij G Newbie

      Hello,

      I am new to the whole world of Java, JEE, EJB, XML, JBoss. I am trying to code up the simple example that is provided in Chapter 4 of the book Enterprise JavaBeans 3.0. I am having a few problems. I hope to get some pointers here.

      The project has 4 files:
      a) An entity bean: User
      b) A stateless session bean: UserRegistrationSessionBean
      c) A remote interface: UserRegistrationRemote
      d) A client file that creates and then looks up a user.

      --------------------------------------------------------------------------

      First my setup:
      Java: jdk1.6.0_12
      JBoss: jboss-5.0.0-GA
      Ant: apache-ant-1.7.1
      OS: Windows XP
      All my java files, build files are in the same directory.

      --------------------------------------------------------------------------

      Second, the problem.
      When I use the build.xml file, the compiler complains:


      jo\ejb\build.xml:21: The element type "path" must be terminated by the matching end-tag "<//path>".


      The corresponding XML code snippet in build.xml (copied from book) is:
       <path id="classpath">
       <fileset dir="${basedir}"/>
       <include name="*.jar"/>
       </fileset>
       <pathelement location="${build.classes.dir}"/>
       <pathelement location="${basedir}/client-config"/>
       </path>
      


      Now, when I change the above to:
       <path id="classpath">
       <pathelement location="${basedir}"/> <=== Changed this
       <pathelement location="${build.classes.dir}"/>
       <pathelement location="${basedir}/client-config"/>
       </path>
      

      The build proceeds but I get the following compiler errors.

      C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.0.GA\apps\mo
      jo\ejb>ant
      Buildfile: build.xml

      prepare:
      [mkdir] Created dir: C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jd
      k6\jboss-5.0.0.GA\apps\mojo\ejb\build
      [mkdir] Created dir: C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jd
      k6\jboss-5.0.0.GA\apps\mojo\ejb\build\classes

      compile:
      [javac] Compiling 4 source files to C:\Documents and Settings\Dan\Desktop\jb
      oss-5.0.0.GA-jdk6\jboss-5.0.0.GA\apps\mojo\ejb\build\classes
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationRemote.java:5: '.' expected
      [javac] import User;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationRemote.java:5: ';' expected
      [javac] import User;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationRemote.java:7: class, interface, or enum expe
      cted
      [javac] @Remote
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationSessionBean.java:8: '.' expected
      [javac] import Cabin;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationSessionBean.java:8: ';' expected
      [javac] import Cabin;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\UserRegistrationSessionBean.java:10: class, interface, or enu
      m expected
      [javac] @Stateless
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\client.java:1: '.' expected
      [javac] import UserRegistrationRemote;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\client.java:1: ';' expected
      [javac] import UserRegistrationRemote;
      [javac] ^
      [javac] C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.
      0.GA\apps\mojo\ejb\client.java:2: class, interface, or enum expected
      [javac] import User;
      [javac] ^
      [javac] 9 errors

      BUILD FAILED
      C:\Documents and Settings\Dan\Desktop\jboss-5.0.0.GA-jdk6\jboss-5.0.0.GA\apps\mo
      jo\ejb\build.xml:38: Compile failed; see the compiler error output for details.

      --------------------------------------------------------------------------

      Finally the code:

      There are 5 files:

      1) User.java:
      import javax.persistence.*;
      @Entity
      @Table(name="USER")
      
      public class User implements java.io.Serializable {
       private String id;
       private String email;
       private String password;
       private String affiliation;
      
       @Id
       @Column(name="EMAIL")
       public String getEmail() { return email; }
       public void setEmail(String new_email) { email = new_email; }
      
       @Column(name="ID")
       public String getId() { return id; }
       public void setId(String new_id) { id = new_id; }
      
       @Column(name="PASSWORD")
       public String getPassword() { return password; }
       public void setPassword(String new_password) { password = new_password; }
      
       @Column(name="AFFILIATION")
       public String getAffiliation() { return affiliation; }
       public void setAffiliation(String new_affiliation) { affiliation = new_affiliation; }
      
      }
      

      --------------------------------------------------------------------------

      2) UserRegistrationRemote.java
      import javax.ejb.Remote;
      import User;
      
      @Remote
      public interface UserRegistrationRemote {
       public void registerUser(User user);
       public User findUser(String email);
      }
      

      --------------------------------------------------------------------------

      3) UserRegistrationSessionBean.java
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      
      import javax.persistence.PersistenceContext;
      import User;
      
      @Stateless
      public class UserRegistrationSessionBean implements UserRegistrationRemote {
       @PersistenceContext
      (unitName="user")
      private EntityManager manager;
      
       public void registerUser(User user) {
       manager.persist(user);
       }
      
       public User findUser(String email) {
       return manager.find(User.class, email);
       }
      }
      

      --------------------------------------------------------------------------

      4) client.java
      import UserRegistrationRemote;
      import User;
      
      import javax.naming.IntialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;
      
      import javax.rmi.PortableRemoteObject;
      
      public class Client {
       public static void main (String[] args) {
       try {
       Context jndiContext = getInitialContext();
       Object ref = jndiContext.lookup("UserRegistrationSessionBean/remote");
       UserRegistrationRemote dao = (UserRegistrationRemote)PortableRemoteObject.narrow(ref, UserRegistrationRemote.class);
      
       User usr = new User();
       usr.setEmail("world@peace.com");
       usr.setId("us");
       usr.setPassword("test");
       usr.setAffiliation("world");
      
       dao.registerUser(usr);
      
       User res_usr = dao.findUser("world@peace.com");
       System.out.println("Email: " + res_usr.getEmail());
       System.out.println("Id: " + res_usr.getId());
       System.out.println("Password: " + res_user.getPassword());
       System.out.println("Affiliation: " + res_usr.getAffiliation());
       }
       catch (javax.naming.NamingException ne) {
       ne.printStackTrace();
       }
       }
      
       public static Context getInitialContext() throws javax.naming.NamingException {
       return new javax.naming.InitialContext();
       }
      }
      

      --------------------------------------------------------------------------

      5) build.xml
      <?xml version="1.0"?>
      
       <!-- Build file for first project for of JBoss -->
       <project name="EJB Build for Mojo" default="ejbjar" basedir=".">
      
       <!-- Standard Properties -->
       <property environment="env"/>
       <property name="src.dir" value="${basedir}"/>
       <property name="lib.dir" value="${basedir}/lib"/>
       <property name="jboss.dir" value="${env.JBOSS_HOME}"/>
       <property name="jboss.deploy.dir" value="${jboss.dir}/server/default/deploy"/>
       <property name="build.dir" value="${basedir}/build"/>
       <property name="build.classes.dir" value="${build.dir}/classes"/>
      
      
      
       <!-- Next, specify where the client app is. client-config which has JNDI properties -->
       <path id="classpath">
       <pathelement location="${basedir}"/>
       <pathelement location="${build.classes.dir}"/>
       <pathelement location="${basedir}/client-config"/>
       </path>
      
       <!-- Create directories to place compiled files -->
       <property name="build.classpath" refid="classpath"/>
       <target name="prepare" >
       <mkdir dir="${build.dir}"/>
       <mkdir dir="${build.classes.dir}"/>
       </target>
      
      
       <!-- Now compile -->
       <target name="compile" depends="prepare">
       <javac srcdir="${src.dir}"
       destdir="${build.classes.dir}"
       debug="on"
       deprecation="on"
       optimize="off"
       includes="**">
       <classpath refid="classpath"/>
       </javac>
       </target>
      
      
       <!-- Create EJB-JAR and place it in deploy directory of JBoss server -->
       <target name="ejbjar" depends="compile">
       <jar jarfile="build/mojo.jar">
       <fileset dir="${build.classes.dir}">
       <include name="*.class"/>
       <include name="*.class"/>
       </fileset>
       <fileset dir="${src.resources}/">
       <include name="**/*.xml"/>
       </fileset>
       </jar>
       <copy file="build/mojo.jar "
       todir="${jboss.home}/server/default/deploy"/>
       </target>
      
      
       <!-- Now run the client -->
       <target name="run.client" depends="ejbjar">
       <java classname="Client" fork="yes" dir=".">
       <classpath refid="classpath"/>
       </java>
       </target>
      
       <!-- Clean the database - only when JBoss is not running -->
       <target name="clean.db">
       <delete dir="${jboss.home}/server/default/db/hypersonic"/>
       </target>
      
       <!-- Clean up and undeploy -->
       <target name="clean">
       <delete dir="${build.dir}"/>
       <delete file="${jboss.home}/server/default/deploy/mojo.jar"/>
       </target>
      
       </project>
      
      

      --------------------------------------------------------------------------


        • 1. Re: A true newbie -- Please help!
          Peter Johnson Master

          Change this:

          <fileset dir="${basedir}"/>
           <include name="*.jar"/>
          </fileset>


          to this:

          <fileset dir="${basedir}" >
           <include name="*.jar"/>
          </fileset>


          (drop the '/' near end of first line)

          • 2. Re: A true newbie -- Please help!
            Rij G Newbie

            Thanks Peter. That fixed the error from the XML.

            But my java source are still not compiling (see messages above).

            The errors are consistently in the import, when I am import-ing my own class. What's wrong with that?

            Sorry for asking you to be babysit me. Although I am a baby in this area, so maybe it's okay! :)

            I do appreciate your time.

            • 3. Re: A true newbie -- Please help!
              Peter Johnson Master

              Remove the statements:

              import User;
              import UserRegistrationRemote;

              from all the source files. You never have to import classes that are in your current package. And by the way, having package-less classes is not a good idea.

              • 4. Re: A true newbie -- Please help!
                Rij G Newbie

                Ok, I was able to successfully build - or so I thought since my window showed the message "BUILD SUCCESSFUL".

                However, when I checked the server log, there were a bunch of error messages. I wont include all of that here. But from checking the forums, it seemed that there was a problem in my persistence.xml file

                First off, here is my persistence.xml:

                <persistence>
                 <persistence-unit>
                 <name>mojo</name>
                 <jta-data-source>java:/DefaultDS</jta-data-source>
                 <properties>
                 <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                 </properties>
                 </persistence-unit>
                </persistence>
                


                Now, the next thing I checked was where to place persistence.xml. From the JBoss docs, I learnt the following:

                You must also define a persistence.xml file that resides in the META-INF folder of the .jar file.


                So in the directory where I have my EJB source files, I created a sub-directory META-INF directory and put persistence.xml in it. Incidentally, I have another sub-directory called client-config which has jndi.properties file. So now, my director structure looks like this:

                {DIR} client-config
                {DIR} META-INF
                build.xml
                Client.java
                User.java
                UserRegistrationRemote.java
                UserRegistrationSessionBean.java
                5 File(s) 5,908 bytes


                Ok now, I run my build. Here is the relevant code which creates the jar file:
                 <!-- Create EJB-JAR and place it in deploy directory of JBoss server -->
                 <target name="ejbjar" depends="compile">
                 <jar jarfile="build/mojo.jar">
                 <fileset dir="${build.classes.dir}">
                 <include name="*.class"/>
                 <include name="*.class"/>
                 </fileset>
                 <fileset dir="${basedir}/META-INF">
                 <include name="*.xml"/>
                 </fileset>
                 </jar>
                 <copy file="build/mojo.jar "
                 todir="${jboss.deploy.dir}"/>
                 </target>
                


                Now, I go on to check the mojo.jar file using the tar tf mojo.jar command.
                Funnily, persistence.xml gets pulled out of the META-INF directory and gets placed in the source (one level higher) directory. Here are the results of the command:

                META-INF/
                META-INF/MANIFEST.MF
                Client.class
                User.class
                UserRegistrationRemote.class
                UserRegistrationSessionBean.class
                persistence.xml


                That doesn't seem right to me. So my questions are: Is my mojo.jar correct? If not, what am I doing wrong?

                I don't know if this will solve the original messages in the server log. But, we will work on it gradually.

                Thank you for your patience in reading my extra long posts. But from my own experience in other forums, I also know that the best way for getting help is to include as much relevant information as possible. :)

                Thanks, Rij

                ----
                P.S: Peter, thanks for the note on packages. I will get into packages eventually. For now, I am just trying to get a hold on how to put the pieces together to get a EJB app running.

                • 5. Re: A true newbie -- Please help!
                  Peter Johnson Master

                  Change your jar task, the part for including persistence.xml, as follows:

                  <fileset dir="${basedir}">
                   <include name="META-INF/*.xml"/>
                  </fileset>


                  Your build directory layout has room for improvement. Personally, I prefer the directory structured enforced by Maven (or a slightly-modified version of that stucture). This structure clearly separates source, build and built/created artifacts. Your current layout has all of these artifacts mixed together into a single directory which makes setting up filesets for various ant tasks more complex than what is necessary.

                  I also highly recommend that you add package declarations into your Java source files. I have seen issues with using package-less classes and chasing down such an issue is something that you should not have to worry about. Also, I don't want to have to research if package-less classes are an issue in EJB.

                  Here are my recommendations:

                  1) Add the following line as the first line to each of your Java source files:

                  package org.rij;


                  2) Change your directory structure so that it looks like this:

                  build.xml
                  src/main/java/org/rij/*.java (all your source code goes here)
                  src/main/resources/META-INF/persistence.xml
                  src/main/resources/jndi.properties (see note below)

                  3) After the build is done, it should generate these artifacts:

                  target/classes/org/rij/*.class (all of the class files)
                  target/classes/META-INF/persistence.xml
                  target/mojo.jar

                  4) Change your build.xml to reflect the above inputs and outputs. I think you will find that the task definitions become much easier. For example, the jar task, which runs after the javac task which compiles the src/main/java source files to target/classes, and the copy task which copies the contents of src/main/resources to target/class becomes simply:

                  <jar jarfile="target/mojo.jar" basedir="target/classes" />


                  No messy includes or excludes!

                  Here are excerpts for the javac and copy task mentioned above, showing the correct directory references (I hard-coded them, you will of course want to set properties and use those)

                  <javac srcdir="src/main/java" destdir="target/classes" ... />
                  
                  <copy todir="target/classes">
                   <fileset dir="src/main/resources" />
                  </copy>


                  P.S. I hope I don't have too many typos in my code examples...

                  • 6. Re: A true newbie -- Please help!
                    Rij G Newbie

                    Ok, I followed the instructions, organized my code in packages and cleaned up the build.xml.

                    Now, my mojo.jar file is correctly reflecting the directory structure.

                    But the server is still showing errors when I try to build. Since it seems to be complaining about persistence, here is my persistence.xml:

                    <persistence>
                     <persistence-unit>
                     <name>mojo</name>
                     <jta-data-source>java:/DefaultDS</jta-data-source>
                     <properties>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     </properties>
                     </persistence-unit>
                    </persistence>
                    


                    And here is the initial part of the server error message:

                    16:48:23,915 ERROR [AbstractKernelController] Error installing to Parse: name=vf
                    szip:/C:/Documents%20and%20Settings/Dan/Desktop/jboss-5.0.0.GA-jdk6/jboss-5.0.0.
                    GA/server/default/deploy/mojo.jar state=Not Installed mode=Manual requiredState=
                    Parse
                    org.jboss.deployers.spi.DeploymentException: Error creating managed object for v
                    fszip:/C:/Documents%20and%20Settings/Dan/Desktop/jboss-5.0.0.GA-jdk6/jboss-5.0.0
                    .GA/server/default/deploy/mojo.jar
                    at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentExcept
                    ion(DeploymentException.java:49)
                    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithO
                    utput.createMetaData(AbstractParsingDeployerWithOutput.java:337)
                    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithO
                    utput.createMetaData(AbstractParsingDeployerWithOutput.java:297)
                    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithO
                    utput.createMetaData(AbstractParsingDeployerWithOutput.java:269)
                    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithO
                    utput.deploy(AbstractParsingDeployerWithOutput.java:230)
                    at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(Deployer
                    Wrapper.java:171)
                    at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(Deployer
                    sImpl.java:1439)
                    at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
                    rst(DeployersImpl.java:1157)
                    at org.jboss.deployers.plugins.deployers.DeployersImpl.install(Deployers
                    Impl.java:1098)
                    at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
                    ctControllerContext.java:348)
                    at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
                    oller.java:1598)
                    at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
                    ctController.java:934)
                    at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
                    actController.java:1062)
                    at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
                    actController.java:984)
                    at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
                    ller.java:822)
                    at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
                    ller.java:553)
                    at org.jboss.deployers.plugins.deployers.DeployersImpl.process(Deployers
                    Impl.java:781)
                    at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeploye
                    rImpl.java:545)
                    at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDSca
                    nner.java:290)
                    at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScan
                    ner.java:221)
                    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:44
                    1)
                    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java
                    :317)
                    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
                    access$101(ScheduledThreadPoolExecutor.java:98)
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
                    runPeriodic(ScheduledThreadPoolExecutor.java:181)
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
                    run(ScheduledThreadPoolExecutor.java:205)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
                    utor.java:886)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
                    .java:908)
                    at java.lang.Thread.run(Thread.java:619)
                    Caused by: org.jboss.xb.binding.JBossXBException: Failed to parse source: Failed
                    to resolve schema nsURI= location=persistence
                    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBPars
                    er.java:203)
                    at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java
                    :168)
                    at org.jboss.deployers.vfs.spi.deployer.JBossXBDeployerHelper.parse(JBos
                    sXBDeployerHelper.java:199)
                    at org.jboss.deployers.vfs.spi.deployer.JBossXBDeployerHelper.parse(JBos
                    sXBDeployerHelper.java:170)
                    at org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer.parse(Sch
                    emaResolverDeployer.java:132)
                    at org.jboss.deployers.vfs.spi.deployer.SchemaResolverDeployer.parse(Sch
                    emaResolverDeployer.java:118)
                    at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parse
                    AndInit(AbstractVFSParsingDeployer.java:256)
                    at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parse
                    (AbstractVFSParsingDeployer.java:188)
                    at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithO
                    utput.createMetaData(AbstractParsingDeployerWithOutput.java:323)
                    ... 27 more
                    Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to resolve schem
                    a nsURI= location=persistence
                    at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startE
                    lement(SundayContentHandler.java:313)
                    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHan
                    dler.startElement(SaxJBossXBParser.java:401)
                    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Sour
                    ce)
                    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Sou
                    rce)
                    at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Sourc
                    e)
                    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unkn
                    own Source)
                    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.s
                    canRootElementHook(Unknown Source)
                    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
                    Dispatcher.dispatch(Unknown Source)
                    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
                    known Source)
                    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Sour
                    ce)
                    at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBPars
                    er.java:199)
                    ... 35 more
                    16:48:24,306 WARN [HDScanner] Failed to process changes
                    org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incompl
                    ete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

                    *** CONTEXTS IN ERROR: Name -> Error

                    vfszip:/C:/Documents%20and%20Settings/Dan/Desktop/jboss-5.0.0.GA-jdk6/jboss-5.0.
                    0.GA/server/default/deploy/mojo.jar -> org.jboss.xb.binding.JBossXBRuntimeExcept
                    ion: Failed to resolve schema nsURI= location=persistence



                    • 7. Re: A true newbie -- Please help!
                      Peter Johnson Master

                      I was going to point this out earlier and completely forgot about it - get JBoss AS out of Documents and Settings! Spaces in path names cause certain Java libraries fits. I have mine at d:\opt\jboss\jboss-5.0.0.GA. In fact, I don't even let the JDK install itself on Program Files, mine is at c:\apps\Java\jdk1.6.0_12. (You can simply move or copy the JDK and change JAVA_HOME accordingly - no need to reinstall.)

                      • 8. Re: A true newbie -- Please help!
                        Rij G Newbie

                        Ok, I changed my jdk and JBoss directory.

                        But I still get the above error.

                        • 9. Re: A true newbie -- Please help!
                          Peter Johnson Master

                          Have you posted the full contents of persistence.xml? If so, try changing the opening 'persistence' tag to:

                          <persistence
                           xmlns="http://java.sun.com/xml/ns/persistence"
                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                           version="1.0">





                          • 10. Re: A true newbie -- Please help!
                            Peter Johnson Master

                            A few more changes to the persistence.xml file - there is no 'name' element, and you need to make the value for name match the name specifed in @PersistenceContext(unitName="user"). So here is the updated persistence.xml file that should work:

                            <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                             version="1.0">
                             <persistence-unit name="user" >
                             <jta-data-source>java:/DefaultDS</jta-data-source>
                             <properties>
                             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                             </properties>
                             </persistence-unit>
                            </persistence>


                            And one more thing. You don't need PortableRemoteObject.narrow. This will work:

                            UserRegistrationRemote dao = (UserRegistrationRemote)jndiContext.lookup("UserRegistrationSessionBean/remote");


                            • 11. Re: A true newbie -- Please help!
                              Rij G Newbie

                              I am traveling for the next few days (cold D.C. from warm L.A.) but will try your suggestions as soon as I am back.

                              • 12. Re: A true newbie -- Please help!
                                Rij G Newbie

                                Alright, I am back.

                                So I tried with your persistence.xml - and it works! It's the extra information (xmlns, xsi) that did the trick because I did have the name specified in my original persistence.xml. I gotta figure out what that extra bit does.

                                Anyhow, moving on, I tried to run the Client. But the JVM is complaining that the class cannot be found. Now I have a question regarding this. Does the JVM look for Client.class in the EJB-JAR file or the directory where the classes had been generated and placed during compilation?

                                Just to refresh, my directory structure looks like this:

                                build.xml
                                src/main/java/org/rij/*.java
                                src/main/resources/META-INF/persistence.xml
                                src/main/resources/jndi.properties

                                target/classes/org/rij/*.class (all of the class files)
                                target/classes/META-INF/persistence.xml
                                target/mojo.jar

                                Also. the part of build file that runs the client is as follows:

                                 <target name="run.client" depends="ejbjar">
                                 <java classname="Client" fork="yes" dir=".">
                                 <classpath refid="classpath"/>
                                 </java>
                                 </target>
                                


                                Since the classpath is important, here is the relevant part of the build file that sets the classpath.
                                 <property environment="env"/>
                                 <property name="src.dir" value="${basedir}/src/main/java"/>
                                 <property name="src.resources" value="${basedir}/src/main/resources"/>
                                 <property name="jboss.dir" value="${env.JBOSS_HOME}"/>
                                 <property name="jboss.deploy.dir" value="${jboss.dir}/server/default/deploy"/>
                                 <property name="target.dir" value="${basedir}/target"/>
                                 <property name="target.classes.dir" value="${basedir}/target/classes"/>
                                 <property name="common.lib.one" value="C:/opt/jboss-5.0.0.GA/common/lib"/>
                                 <property name="common.lib.two" value="C:/opt/jboss-5.0.0.GA/client"/>
                                
                                
                                
                                 <!-- Next, specify where the client app is. client-config which has JNDI properties -->
                                 <path id="classpath">
                                 <fileset dir="${common.lib.one}">
                                 <include name="*.jar"/>
                                 </fileset>
                                 <fileset dir="${common.lib.two}">
                                 <include name="*.jar"/>
                                 </fileset>
                                 <pathelement location="${target.dir}"/>
                                 <pathelement location="${target.classes.dir}"/>
                                 </path>
                                


                                The second pathelement tag shows the exact location of the class, in case the JVM looks for the class file specifically. If instead the EJB-JAR is used, then I have not explicitly mentioned that. But my assumption is that the deploy directory in default server is automatically scanned?

                                -Rij

                                • 13. Re: A true newbie -- Please help!
                                  Rij G Newbie

                                  Ok, I fixed the issues.

                                  The problem was that the classname in the java tag did not reflect the package structure. Once I fixed that, it ran just fine.

                                  I also found out that the system picks the Client.class from the EJB-JAR and not from the target directory. However, I had explicitly specify the path to the jar (which is the deploy directory in the server). Is there a way to automatically include that in the classpath?

                                  • 14. Re: A true newbie -- Please help!
                                    Peter Johnson Master

                                    The JVM will pick a class from the first entry in the classpath that contains it. If you run Ant with the '-v' option it should give you the full classpath that it is using to run the client.

                                    You can add the "-verbose:class" JVM option to your 'java' task for the client. This option causes the JVM to print out the classpath location of each class file loaded.

                                    Personally, I tend to either type the command line for my client, or generate a bat or shell script to run the client. rather than running the client via Ant. This way I know exactly what classpath I am getting.