users@jax-rpc.java.net

Re: Properties for services

From: Alexi Polenur <apolenur_at_YAHOO.COM>
Date: Fri, 18 Oct 2002 06:25:59 -0700

Hi Dima,

The name can be hardcoded in your code.
Let say you have a class com.mycomp.myprj.MyClass and
inside some meothod of this class you call
this.getClass().getResourceAsSteam("MyConfig.xml");
As a result of this call JVM will search you Java
class path for the file com.mycomp.myprj.MyClass.
So in this case you should keep your configuration
file in the same directory as your MyClass file.

If you used getResourceAsStream("/MyConfig.xml"). The
file will be looked for in the root of your classpath.
So it can be in the classes directory of you WAR or
anywhere in the class path for you execution
environment.

BTW I don't see big problem if conf. file is part of
the WAR. After deployment all containers I know expand
WAR into filesystem, so user can go and modify
configuration they want. More over I think that
package configuration file into WAR is the way to go
because otherwise you have to send user to files- WAR
and config file with instruction "Please put the
config in such and such location ...".

Regards Alexi



--- Dima Sennikov <D.Sennikov_at_PROZA.LVIV.UA> wrote:
> Hello,
>
> getResourceAsStream(name)
> name - name of the desired resource
>
> But How get name? All classes and resources packed
> to war file. If
> user want to change configuration he must repack
> war file. It is not
> good. I can read file from file system like File
> conf = new
> File(path); How get path? I can not use
> "c:\conf.xml" because Linux
> has not disk c. Best variant is got location to my
> war file. like
> "C:\jwsdp-1_0\webapps" or like
> "/home/local/jwsdp-1_0/webapps". and
> load file File cong = new File(warLocation,
> "conf.xml" How can I do
> it? or another way?
>
> AP> Hi,
>
> AP> One of the convinient way to load resources for
> your
> AP> application, like XML configuration file is to
> use
>
> AP> getResourceAsStream(String)
>
> AP> method available on Class object.
>
> AP> In your code where you need to load the file you
> can
> AP> do
> AP> something like that:
>
> AP> this.getClass().getResourceAsStream()
>
> AP> The resource will be looke up and loaded by the
> same
> AP> class loader which was used to load your class.
>
> AP> Read JavaDoc for details.
>
> AP> Alexi
>
> AP> --- Dima Sennikov <D.Sennikov_at_PROZA.LVIV.UA>
> wrote:
> >> Hello All,
> >>
> >> My Webservice has configuration. I store it in
> xml
> >> file. WebService
> >> has not ServletContext or any Context. I try
> store
> >> path to xml file
> >> in System Properties, i do not get result. How
> can I
> >> set path to xml
> >> and get it in web Service methods.
> >>
> >> --
> >> Best regards,
> >> Dima
> AP> mailto:D.Sennikov_at_proza.lviv.ua
>
>
> AP>
> __________________________________________________
> AP> Do you Yahoo!?
> AP> Faith Hill - Exclusive Performances, Videos &
> More
> AP> http://faith.yahoo.com
>
>
>
> --
> Best regards,
> Dima
mailto:D.Sennikov_at_proza.lviv.ua


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com