Discussions

EJB programming & troubleshooting: reading file from EJB

  1. reading file from EJB (2 messages)

    Does anyone know how I specify that I want to read a user defined XML file from say the "conf" directory in a J2EE appserver environment (say Weblogic or Jboss) ? The problem I am having is specifying a relative directory location.

    Threaded Messages (2)

  2. reading file from EJB[ Go to top ]

    You should not be reading files from the hard drive in an EJB, period.

    What you can do is put the file in your classpath and then use the getResourceAsStream call to read it in.

    If you insist on going against standards, jboss provides environment variables, so could use, say ${jboss.server.home}/conf to get to the directory. Not sure of the exact name in jboss or what other servers might do.
  3. reading file from EJB[ Go to top ]

    Thanks for your reply Nathan.

    I think you are correct in saying that (according to the J2EE spec) you are not supposed to read files from the hard drive.

    In reality it is essential in some circumstances to be able to reference say an XML config file (from an EJB or helper class) and for this file to be updated (and deployed) separately from any jar which may utilise it. For example if the parameters were environment specific you wouldn't want to have to re-create the Jar (with an XML file in it) each time you deployed it into another environment

    I checked the J2EE spec and none of the reasons for not doing reads apply to our situation so I will probably use an environment variable as you suggested.

    Thanks again for your help.