4 Replies Latest reply on Apr 5, 2002 10:42 AM by henneschen

    Where should I put user property files?

    garymarsh

      Hi;
      I have an entity EJB that needs to access a property file that I have included in the .jar file. My ejb-jar.xml file looks like this :


      Client Entity Bean
      <ejb-name>Client</ejb-name>
      com.payroll.ClientHome
      com.payroll.Client
      <ejb-class>com.payroll.ClientBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.payroll.ClientPK</prim-key-class>
      <cmp-field><field-name>clientId</field-name></cmp-field>
      <primkey-field>clientId</primkey-field>
      False

      <env-entry>
      The Properties file
      <env-entry-name>PayeProperties</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>Paye.properties</env-entry-value>
      </env-entry>



      =============

      When I do an initialContext() lookup I find the correct contents "Paye.properties" but when I type to read the file I get an error saying :

      [Default] java.io.FileNotFoundException: Paye.properties (The system cannot find the file specified)
      [Default] at java.io.FileInputStream.open(Native Method)

      ====

      So where do I need to put the file in my .jar file so that when I HotDeploy the program can find it?

      Thanks,

      Gary

        • 1. Re: Where should I put user property files?
          marc.fleury

          try

          Thread.currentThread().getContextClassLoader().getResource(<your file>);

          and make sure to put the file at the root of your jar.

          marcf

          • 2. Re: Where should I put user property files?
            garymarsh

            mark fleury;

            I tried your suggestion and it still doesn't find the file.

            here is my code :

            public void readInStream( String propFileName )throws IOException
            {
            log.debug("in readInStream() : propFileName = "+propFileName);

            URL url = Thread.currentThread().getContextClassLoader().getResource("/"+propFileName);

            if( url == null )
            log.debug("URL for propFile is null");
            else
            log.debug("URL for propFile is "+ url.toString());


            InputStream in = url.openStream();
            if( in == null )
            {
            log.debug("InStream = null");
            throw new IOException("InStream is Null in readInStream.");
            }

            Properties p = new Properties();
            p.load( in );

            in.close();

            System.setProperties(p);

            }
            ==========

            here is the log output.

            [PropertyReader] in readInStream() : propFileName = Paye.properties
            [PropertyReader] URL for propFile is null
            [Default] null
            [Client] TRANSACTION ROLLBACK EXCEPTION:null
            Embedded Exception
            null; nested exception is:
            javax.ejb.EJBException: null
            Embedded Exception
            null
            [Client] java.lang.NullPointerException
            [Client] at com.paye.payroll.ClientBean.ejbCreate(ClientBean.java:146)
            [Client] at java.lang.reflect.Method.invoke(Native Method)
            [Client] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:204)
            [Client] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:616)
            [Client] at java.lang.reflect.Method.invoke(Native Method)
            [Client] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:843)
            [Client] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:231)
            [Client] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:154)
            [Client] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:108)
            [Client] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
            [Client] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
            [Client] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
            [Client] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:103)
            [Client] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
            [Client] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:420)
            [Client] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:372)
            [Client] at java.lang.reflect.Method.invoke(Native Method)
            [Client] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
            [Client] at sun.rmi.transport.Transport$1.run(Transport.java:152)
            [Client] at java.security.AccessController.doPrivileged(Native Method)
            [Client] at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
            [Client] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
            [Client] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
            [Client] at java.lang.Thread.run(Thread.java:484)


            Any suggestions??

            Gary

            • 3. Re: Where should I put user property files?
              garymarsh

              Mark;

              I found that if I removed the "/" from in front of the file name your suggestion worked.

              thanks,

              Gary

              • 4. Re: Where should I put user property files?
                henneschen

                I have the same problem, but your solution only gives the path to the directory of the starting call. e. g. C:/JBoss-2.4.4_Tomcat-4.0.1/jboss/bin/ and not the deployment directory.