Is a resource preferred to a property file, or are they the same thing?
 
Ivan
----- Original Message -----
Sent: Monday, July 16, 2001 2:12 AM
Subject: Re: [JBoss-user] Setting & Accessing Resource Files in JBoss

Hi Burkard,

As far as i know you should not access files directly through file IO operations, or make assumptions on an existing filesystem
at all in EJB's.
The "/" in a resource name is relatively seen, the package root from the class that calls the getClass().getResourceAsStream() method. This way you can
package resources with the jar and don't have to create and manage external directorier (on different operating systems). The "/" used in resources works for all operating systems.

Cheers

Lorenzo

SurfKitchen, Inc

Burkhard Vogel wrote:
073c01c10d43$820f8670$[EMAIL PROTECTED]" type="cite">
Hi,
just guessing but wouln't you lookup the file from the root-dir if you use
/config/ConfigFile.xml??? you are getting the string correctly, right?
so the two alternatives would be using something like config/ConfigFile.xml,
but I think that will be JBOSS_HOME/bin/config/ConfigFile.xml of suit your
/config to match someplace in your file structure, i.e.
../conf/tomcat/ConfigFile.xml.
Burkhard
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, July 14, 2001 1:35 AM
Subject: Re: Re: [JBoss-user] Setting & Accessing Resource Files in JBoss


Wow, Thanks a lot Lorenzo... Now I have better hopes!

I still have some Issues with this:

I made it to code and deploy a Session bean that access to a resource file
from the source code you send me. I got the correct name and location of the
file with
theResourceName = (String)theInitialContext.lookup("java:comp/env/" +
anEvironmentName);
here I can see the exact valu I gave in the deployment descriptor
(<env-entry-value>/config/ConfigFile.xml</env-entry-value>), I also deployed
the file same name and in the same directory in the .jar file.
But with

java.io.InputStream theInputStream =
getClass().getResourceAsStream(theResourceName);
I allways get null!! :( (of course I can´t read the Stream afterwards,
then I get the NullPointerException)
I´ve been working around with this, but nothing helped. Do you guys have
any clue?
Jorge Suarez
Commexnet Co.
Medellin, Colombia

De: Lorenzo Resta <[EMAIL PROTECTED]>
Fecha: 13-Jul-2001 07:09
Para: [EMAIL PROTECTED]
Asunto: Re: [JBoss-user] Setting & Accessing Resource Files in JBoss

Hi,

You can do something like this:

First create an environment entry in your ejb-jar.xml file like:

<env-entry>
<env-entry-name>ConfigFile</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/config/ConfigFile.xml</env-entry-value>
</env-entry>


private String getResourceNameFromEnvironment(String
anEnvResourceName) throws NamingException{
     String theResourceName;
InitialContext theInitialContext = new InitialContext();

theResourceName = (String)theInitialContext.lookup("java:comp/env/"
+ anEvironmentName);
     return theResourceName;
}

private void loadResource(String aEnvResourceName){
String theResourceName =
getResourceNameFromEnvironment(aEnvResourceName);
     java.io.InputStream theInputStream =
getClass().getResourceAsStream(theResourceName);
   }

Cheers


Lorenzo

SurfKitchen Inc.


[EMAIL PROTECTED] wrote:

Hi to all!
I´m almost a newbye to JBoss (and even to J2EE development). I have
some issues to be covered in the project we are developing, many of them aim
to be solved with having access to a repository and "read" data from there.
Since we don´t want to use the database for that and we cannot access
regular files from a EJB according to the J2EE specs, I need to know if it´s
possible to deploy a kind of "resource" file wich can hold my data and
access it trought the context or something like that.
If this is possible.... What´s the how to? Where can I find
documentation about it? Any alternative?
Thanks a lot!!
Jorge Suarez
Commexnet Co.
Medellin, Colombia

--------------------------------------------------------------------------
----
Obtén gratis tu cuenta de correo en StarMedia Email.
¡Regístrate hoy mismo!. http://www.starmedia.com/email

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


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user




_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

--------------------------------------------------------------------------
----
Obtén gratis tu cuenta de correo en StarMedia Email.
¡Regístrate hoy mismo!. http://www.starmedia.com/email

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


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to