JSP Properties File Load In / Websphere

Discussion in 'Java' started by RigasMinho, Feb 26, 2007.

  1. RigasMinho

    RigasMinho Guest

    Hello,
    A while back you guys helped me load in a properties file using jsp
    code which went like this:
    properties = new Properties();
    URL myURL=application.getResource("test.properties");
    InputStream in = myURL.openStream();
    properties.load( in );

    That worked 100% well.

    Now i have a question about what to do to read in a file in websphere.

    Like the properites file has a line where i read information from it.
    logfile=/hugelogfile.log

    This file is stored in the webroot directory.

    How do i make it so that the log file is still accessed when in
    websphere?
    do i change the path too:
    logfile=\\\\hugelogfile.log
    or
    logfile=d:\\webroot\\hugelogfile.log

    Anyone know the answer to this?

    Let me know -
    RigasMinho, Feb 26, 2007
    #1
    1. Advertising

  2. RigasMinho

    Lew Guest

    RigasMinho wrote:
    > Hello,
    > A while back you guys helped me load in a properties file using jsp [sic]
    > code which went like this:
    > properties = new Properties();
    > URL myURL=application.getResource("test.properties");
    > InputStream in = myURL.openStream();
    > properties.load( in );


    That's not JSP code, that's Java code.

    > That worked 100% well.
    >
    > Now i have a question about what to do to read in a file in websphere.
    > Like the properites file


    Which properties
    > has a line where i read information from it.
    > logfile=/hugelogfile.log
    >
    > This file is stored in the webroot directory.


    Which directory is that?

    > How do i make it so that the log file is still accessed when in
    > websphere?
    > do i change the path too:
    > logfile=\\\\hugelogfile.log
    > or
    > logfile=d:\\webroot\\hugelogfile.log


    Stay with forward slashes; don't switch to backslashes.

    There are multiple approaches to locating resources in a J[2]EE app. The
    easiest is to put locations in the web.xml deployment descriptor. Others
    involve using relative paths rather than absolute paths, and understanding the
    rules for where a Web app finds things (usually in a directory relative to the
    app server installation or else relative to the classpath, depending on how
    things are invoked).

    Then there is always brute-force hardcoding the full path in at deployment
    time, as in

    logfile = d:/webroot/hugelogfile.log
    (Assumes a Windows system)

    - Lew
    Lew, Feb 26, 2007
    #2
    1. Advertising

  3. RigasMinho wrote:
    > Like the properites file has a line where i read information from it.
    > logfile=/hugelogfile.log
    >
    > This file is stored in the webroot directory.
    >
    > How do i make it so that the log file is still accessed when in
    > websphere?
    > do i change the path too:
    > logfile=\\\\hugelogfile.log
    > or
    > logfile=d:\\webroot\\hugelogfile.log
    >
    > Anyone know the answer to this?


    Any file specification that is valid for Java IO code
    should work fine.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Feb 27, 2007
    #3
  4. RigasMinho

    RigasMinho Guest

    On Feb 26, 5:57 pm, Lew <> wrote:
    > RigasMinho wrote:
    > > Hello,
    > > A while back you guys helped me load in a properties file using jsp [sic]
    > > code which went like this:
    > > properties = new Properties();
    > > URL myURL=application.getResource("test.properties");
    > > InputStream in = myURL.openStream();
    > > properties.load( in );

    >
    > That's not JSP code, that's Java code.
    >
    > > That worked 100% well.

    >
    > > Now i have a question about what to do to read in a file in websphere.
    > > Like the properites file

    >
    > Which properties
    >
    > > has a line where i read information from it.
    > > logfile=/hugelogfile.log

    >
    > > This file is stored in the webroot directory.

    >
    > Which directory is that?
    >
    > > How do i make it so that the log file is still accessed when in
    > > websphere?
    > > do i change the path too:
    > > logfile=\\\\hugelogfile.log
    > > or
    > > logfile=d:\\webroot\\hugelogfile.log

    >
    > Stay with forward slashes; don't switch to backslashes.
    >
    > There are multiple approaches to locating resources in a J[2]EE app. The
    > easiest is to put locations in the web.xml deployment descriptor. Others
    > involve using relative paths rather than absolute paths, and understanding the
    > rules for where a Web app finds things (usually in a directory relative to the
    > app server installation or else relative to the classpath, depending on how
    > things are invoked).
    >
    > Then there is always brute-force hardcoding the full path in at deployment
    > time, as in
    >
    > logfile = d:/webroot/hugelogfile.log
    > (Assumes a Windows system)
    >
    > - Lew


    okay so here's my problem - Thanks Lew by the way.

    when i run the application from my machine (tomcat) and i use the line
    logfile = d:/webroot/hugelogfile.log

    It works and writes to the log file.

    Now the question is when i deploy the application to websphere - how
    do i make it write to the log file that is stored in teh war file.

    Meaning - the war file will have all the source code / all the log
    files. The app needs to somehow find the log file while its stored in
    the war file itself.

    Before I had
    logfile = /hugelogfile.log
    This would find the log file and display it but would never write to
    it.

    This is where my issue lies - i dont get why it would work in tomcat
    (when i specifically tell where the location is) and not work when i
    dont tell where the location is by using /hugelogfile.log
    RigasMinho, Feb 27, 2007
    #4
  5. RigasMinho

    Sem Guest

    On Feb 26, 9:09 pm, Arne Vajhøj <> wrote:
    > RigasMinho wrote:
    > > Like the properites file has a line where i read information from it.
    > > logfile=/hugelogfile.log

    >
    > > This file is stored in the webroot directory.

    >
    > > How do i make it so that the log file is still accessed when in
    > > websphere?
    > > do i change the path too:
    > > logfile=\\\\hugelogfile.log
    > > or
    > > logfile=d:\\webroot\\hugelogfile.log

    >
    > > Anyone know the answer to this?

    >
    > Any file specification that is valid for Java IO code
    > should work fine.
    >
    > Arne


    WebSphere web.xml file and Tomcat web.xml file have some difference.

    When you see the structure it looks the same but there are some
    difference in the two

    The best way is to look this two file and make them useable and then
    you

    Can run your application with Web Sphere. Otherwise you are talking
    two different things

    --sem
    Sem, Feb 27, 2007
    #5
  6. RigasMinho wrote:
    > Now the question is when i deploy the application to websphere - how
    > do i make it write to the log file that is stored in teh war file.
    >
    > Meaning - the war file will have all the source code / all the log
    > files. The app needs to somehow find the log file while its stored in
    > the war file itself.


    You can not write to a log file inside the war file.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Feb 27, 2007
    #6
  7. Sem wrote:
    > WebSphere web.xml file and Tomcat web.xml file have some difference.
    >
    > When you see the structure it looks the same but there are some
    > difference in the two
    >
    > The best way is to look this two file and make them useable and then
    > you
    >
    > Can run your application with Web Sphere. Otherwise you are talking
    > two different things


    I would recommend only using features for web.xml that
    are defined in the servlet specification and therefore
    works in both Tomcat and WebSphere.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Feb 27, 2007
    #7
  8. RigasMinho

    Lew Guest

    RigasMinho wrote:
    > when i run the application from my machine (tomcat) and i use the line
    > logfile = d:/webroot/hugelogfile.log
    >
    > It works and writes to the log file.
    >
    > Now the question is when i deploy the application to websphere - how
    > do i make it write to the log file that is stored in teh war file.


    You can't. You have to have the log file on the host file system somewhere.

    Or are you asking how to make WebSphere use the log file as specified inside
    the WAR? one easy way is to change the properties file in the deployment
    environment after it comes out of the WAR. Another is to build the WAR with
    either a relative filename or an absolute filename relevant for the specific
    host.

    Yet another alternative is to load the properties through a classloader
    (ClassLoader.getResource()) or via related methods that root their search in
    the classpath. The classpath for a Web app is rooted at
    <context>/WEB-INF/classes/.

    Some things with relative pathnames in a Web app come from the context root
    directory, some from the classes/ subdirectory, and some from a path relative
    to the Web container (WebSphere) installation directory.

    > Meaning - the war file will have all the source code / all the log
    > files. The app needs to somehow find the log file while its stored in
    > the war file itself.


    Are you saying that you want the actual log file to reside inside the WAR,
    rather than somewhere else on the app host machine file system? That is not
    possible.

    > This is where my issue lies - i dont get why it would work in tomcat
    > (when i specifically tell where the location is) and not work when i
    > dont tell where the location is by using /hugelogfile.log


    But saying "/hugelogfile.log" does specify a location.

    - Lew
    Lew, Feb 27, 2007
    #8
  9. RigasMinho

    RigasMinho Guest

    On Feb 27, 6:40 pm, Lew <> wrote:
    > RigasMinho wrote:
    > > when i run the application from my machine (tomcat) and i use the line
    > > logfile = d:/webroot/hugelogfile.log

    >
    > > It works and writes to the log file.

    >
    > > Now the question is when i deploy the application to websphere - how
    > > do i make it write to the log file that is stored in teh war file.

    >
    > You can't. You have to have the log file on the host file system somewhere.
    >
    > Or are you asking how to make WebSphere use the log file as specified inside
    > the WAR? one easy way is to change the properties file in the deployment
    > environment after it comes out of the WAR. Another is to build the WAR with
    > either a relative filename or an absolute filename relevant for the specific
    > host.
    >
    > Yet another alternative is to load the properties through a classloader
    > (ClassLoader.getResource()) or via related methods that root their search in
    > the classpath. The classpath for a Web app is rooted at
    > <context>/WEB-INF/classes/.
    >
    > Some things with relative pathnames in a Web app come from the context root
    > directory, some from the classes/ subdirectory, and some from a path relative
    > to the Web container (WebSphere) installation directory.
    >
    > > Meaning - the war file will have all the source code / all the log
    > > files. The app needs to somehow find the log file while its stored in
    > > the war file itself.

    >
    > Are you saying that you want the actual log file to reside inside the WAR,
    > rather than somewhere else on the app host machine file system? That is not
    > possible.
    >
    > > This is where my issue lies - i dont get why it would work in tomcat
    > > (when i specifically tell where the location is) and not work when i
    > > dont tell where the location is by using /hugelogfile.log

    >
    > But saying "/hugelogfile.log" does specify a location.
    >
    > - Lew


    Thanks guys -
    I think what I was asking was impossible to do - although i wonder how
    the developer did this before. I dont think it was in a war file but
    a zip file (is that how weblogic is run?) anyways..

    I just did the solution of storing the log file in another folder off
    another system. And now it works.

    I never knew you couldnt write to a log file inside the war file
    itself.

    THANKS for your help guys.

    PS i hate programming - which is why i'm going to change my career to
    become an head hunter for IT. Let me know if you want to use me to
    represent you. e-mail me at My background is all
    in IT so i know what IT people want in a job. 4 year degree in CS / 1
    year experience in Exchange + Servers / 1 year experience in
    Programming. So why would you want to use me ? Cause i'm garunteeing
    you last recruiter / headhunter you spoke with was some retarded kid
    who just started to do IT recruiting who has no idea what IT is really
    about except "i want to make huge commissions placing people"
    RigasMinho, Mar 1, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sudhir
    Replies:
    1
    Views:
    785
    John C. Bollinger
    Aug 27, 2003
  2. fantasticboogie
    Replies:
    0
    Views:
    353
    fantasticboogie
    Sep 1, 2004
  3. Replies:
    0
    Views:
    4,347
  4. RigasMinho

    Load Java Properties File using JSP

    RigasMinho, Sep 1, 2006, in forum: Java
    Replies:
    9
    Views:
    36,599
    RigasMinho
    Sep 5, 2006
  5. oziris

    JSP & WebSphere 6.0

    oziris, Oct 17, 2006, in forum: Java
    Replies:
    1
    Views:
    608
    Manish Pandit
    Oct 17, 2006
Loading...

Share This Page