Relative path for servlet property file.

I have the following java file. When I use the absolute path for the configFile, it works. I would like to know how I could use it as relative path as in installation, the name of the directory could change.
How do I fix the problem? Thank you.
---------------------- LoadProperties.java ----------------
import java.util.*;
import java.io.*;
public class LoadProperties {
private String driver="";
private String dbURL="";
private String login="";
private String password="";
static public void main(String[] args) {
LoadProperties lp = new LoadProperties();
} // main
public LoadProperties() {
//String configFile = "C:/1LMS/web-app/WEB-INF/config/db.properties";
String configFile = getClass().getResource("config/db.properties").toString(); <--- This line could not find the db.properties file.
Properties Prop = new Properties();
try {
FileInputStream configStream = new FileInputStream(configFile);
Prop.load(configStream);
configStream.close();
} catch(IOException e) {
          System.out.println("Error: Cannot laod configuration file ");
driver =Prop.getProperty("driver");
     dbURL = Prop.getProperty("dbURL");
     login = Prop.getProperty("login");
password = Prop.getProperty("password");
printResult();
} //Load Property
private void printResult() {
     System.out.println("Driver = " + driver);
     System.out.println("dbURL = " + dbURL);
     System.out.println("Login = " + login);
System.out.println("PSWD = " + password);
} // class

hi there,
had the same problem... you need to use following API:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
In your case something like that:
// get the servlet context
ServletContext context = getServletContext();
// directory name where the file is located
String realPath = context.getRealPath("/config");
// get real path to your file
String propertyPath = real+"filename.txt";
hope that helps!!
minu

Similar Messages

  • Using relative path for in file/ftp adapter

    Hi All,
    How to have a relative path for file/ ftp adapter's inbound/outbound operation?
    Example: Consider $ORA_HOME = /home/oracle --> This environment variable can be different on different machines
    i want to drop a file in to $ORA_HOME/folder1/folder2 (Or poll for a file).
    <partnerLinkBinding name="FTP">
    <property name="wsdlLocation">FTP.wsdl</property>
    <property name="out_dir" type="LogicalDirectory">What do i write here???</property>
    <property name="retryInterval">60</property>
    </partnerLinkBinding>
    if i cant configure this in partner link section or in activation agent sction, how else do i achieve this?
    i am using 10.1.3.* version.
    Thanks in advance.
    Roshan.

    You can achive it using the deployment scripts if the directory is changing on the basis of the environment
    If you want to change at run time than you can use the jca properties to set using the variables at runtime.
    Regards,
    Ajay

  • Relative path for files

    hi all,
    I am making a small program that needs to store some of the users preferences in a text file. I want the text file to be in the jar when i am finished and in the same folder as the main class. I am having a problem though with writing to a reading the file in a relative path. when i use "args.txt" it reads to the c:\args.txt and not the folder in which the program runs. Same thing with "\\args.txt" and "/args.txt". Any help? Thanks! :)

    If your file is in the same directory as the program the relative path is simply the file name : "args.txt". Also possible is "./args.txt".
    Keep in mind though that you can't write to a file in a jar, and even reading it is more complicated than with the ordinary I/O classes.
    Look up the getResourceAsStream method in the API (I think it's a method of the ClassLoader class).

  • Any way to avoid absolute path names in property files?

    I would like to create property files that only rely on relative positions
    of files. Is there any way to accomplish this? It would be nice if the
    property file values supported property substitution,
    eg. weblogic.ejb.deploy=%weblogic.system.home%/classes/beanManaged.jar
    Or is it safe to simply use relative paths for all file references?
    eg. weblogic.ejb.deploy=classes/beanManaged.jar
    Thank you for any suggestions.
    Marko.

    Alexander Petrushko wrote:
    >
    Marko Milicevic wrote:
    I would like to create property files that only rely on relative positions
    of files. Is there any way to accomplish this? It would be nice if the
    property file values supported property substitution,
    eg. weblogic.ejb.deploy=%weblogic.system.home%/classes/beanManaged.jar
    Or is it safe to simply use relative paths for all file references?
    eg. weblogic.ejb.deploy=classes/beanManaged.jarRelative paths do not work -- In what version? I've always deployed beans with relative paths. It's
    always worked for me.
    You might also be interested in checking out our EJB 1.1/2.0 beta. The
    new EJB container does not require a weblogic.ejb.deploy line in your
    properties file.
    -- Rob
    I filed an enhnacement request with support
    that was asking for deployment by name and with a relative path, e.g.
    weblogic.ejb.deploy.myBean=classes/beanManager.jar
    The workaround is to do the substitution of %weblogic.system.home% yourself
    as part of the build. If you use Ant as your build tool, you can accomplish
    this with a
    few lines of XML.
    Cheers
    Alex

  • Css/js relative path for embedded server

    We have recently begun using relative paths for css and js files in our deployed applications:
    <link href="../../resources/css/global3.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" src="../../resources/script/globalScript.js" type="text/JavaScript"></script>
    I cannot figure out where to put the resources folder on my local machine so the pages will link correctly when running a project on my embedded server in JDev. Can anyone please help?

    Hi,
    the embedded OC4J has its configuration files at
    \jdeveloper_installdir\jdev\system\oracle.j2ee.<version>\embedded-oc4j
    However, if you use relative addressing then web applications try to find them relative to the public_html directory of the Viewlayer project
    Frank

  • Get the relative path for java class

    How to get Relative path for java class which is inside in web-inf directory in webapps

    ajay.manchu wrote:
    Hi gimbal2,
    My Requirement is i need to run a java class from batch file,when i created batch file in that i need to mention the complete path of the java class,so instead of mentioning that i want to provide only java class name,thats why i asked that one..
    can u help me regarding that....
    Thanks in advanceI wonder how that would work then. Let's take a fictive example. You have a class com.mycompany.myapp.Foo. This would mean that the class is stored in some directory like this:
    c:/webrootdir/myapp/WEB-INF/classes/com/mycompany/myapp/Foo.classTo be able to run such a class from the commandline using Java, you would have to invoke this command:
    java -cp c:/webrootdir/myapp/WEB-INF/classes com.mycompany.myapp.FooHow would knowing the exact path to this class help you?

  • Open module for managing property file and environment variables

    Looking for an open module for managing property files and environment variables (like CLASSPATH) set in a shell script. For handeling properties (preserving comments, supporting includes, appending new entries, and more) I have looked at SuperProperties from openadaptor but find certain functionality lacking. As for interfacing with common shell scripts/files containing setting for CLASSPATH, JAVA_HOME, other system/application variables another type of object editor is needed. Maybe JFIG?
    Any ideas are greatly welcomed.

    You seem wright, you hit a brick wall here with Air to find the location
    of the command console on windows...
    So in fact I never build an exe tool, but this little problem was a nice
    case to test it and I tried it.:
    I downloaded monodevelop
    -GTK# for .NET 2.12.10*
    -MonoDevelop 2.4.2*
       from http://monodevelop.com/Download
    created a console project and had an exe in 5 minutes !
    You can download the findconsole tool and the projectfiles here:
       http://greencollective.nl/temp/dump/findconsole_monoproject.zip
    findconsole.exe will reveal the path/location of cmd.exe on a windows system.
    Cheers,
    Latcho

  • Relative Path for Jquery into Content Editor Web Part

    Hi;
    I'd add a Content Editor Web Part (CEWP) to a web part zone. I'd edit that CEWP in HTML view and add my script which load Jquery and my question :  how to use a relative
    path for Jquery :
    <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true"
      Localizable="false" />
    <script src="/sites/XXX/Style%20Library/Scripts/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    My code
    </script>
    Regards

    Hi;
    Firstly, I have used : 
    <script src="/Style%20Library/Scripts/jquery.min.js" type="text/javascript"></script>
    But any result and any change and If I add /Sites/XXX/ : it works correctly ?
    My code is :
    <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true"
        Localizable="false" />
    <script src="/sites/XXX/Style Library/Scripts/jquery.min.js" type="text/javascript"></script>    
    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(displayTitle, "SP.js");
    var site;
      var context;
      function displayTitle() {
        //Get the current client context
        context = SP.ClientContext.get_current();
        //Add the site to query queue
        site = context.get_web();
        context.load(site);
        //Run the query on the server
        context.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    function onQueryFailed(sender, args) {
      alert('request failed ' + args.get_message() +
        '\n' + args.get_stackTrace());
    function onQuerySucceeded(sender, args) {
        $("#layoutsTable table th span").html("Bienvenue sur le site " + site.get_title() + " - Direction Technique");
        $("#zz17_V4QuickLaunchMenu ul.root li span:contains('Biblioth')").parent().parent().hide();
        $("#zz17_V4QuickLaunchMenu ul.root li span:contains('Listes')").parent().parent().hide();
    </script>

  • Creating cache for multiple property files run time/dynamically.

    Hi,
    I have a requirement, where in I need to create cache for each property file present in a folder at server side or in the lib or resources directory. Please help me how I can do this?
    Thanks.

    ok thank you.
    I follwed this method implementation:
    static HashMap<String, HashMap<Object, String>> cacheHolder = new HashMap<String, HashMap<Object, String>>();
         static HashMap<Object, String>[] cache = new HashMap[2];
         static Integer fileCount = 0;
         static int incrementSize = 2;
    public method1(Map<Object,String>map){
    File file = new File((new StringBuilder(
                             "ABC/XYZ/")).append(value)
                             .toString()); // where value is the file name returned from the external method
                   int newSize = existingMapLength+incrementSize;
                   if (someVal== null) {                    
                        synchronized (fileCount) {
                             int oldSize = cache.length;
                             if(fileCount==cache.length){
                                  HashMap[] oldData = new HashMap[oldSize];
                                  oldData = cache;                              
                                  cache = new HashMap[newSize];
                                  LOGGER.info("New Size added:==>"+cache.length);
                                  for(int i=0;i<oldSize;i++){                                   
                                       cache[i] = oldData;
                                  cache[fileCount] = readExternalPropertiesFile(file); // external method which returns the properties of the file in hashmap
                                  cacheHolder.put(value, cache[fileCount]);                    
                                  keys = cache[fileCount].keySet();
                             else{                         
                             cache[fileCount] = readPropertiesFile(file);
                             cacheHolder.put(value, cache[fileCount]);                    
                             keys = cache[fileCount].keySet();
                             someVal= cache[fileCount];
    fileCount = fileCount + 1;
    Please let me know if any improvemnets are possible.

  • Changing File path for different TIFF files in a For loop

    Hi dear users:
    I am using "IMAQ write TIFF File.vi" that basically writes a TIFF file to a specified file path. However, I would like to CHANGE the file path for each TIFF file i save in a for loop. The reason for this is that the File path has to include the file name and I do not want to write over the same file name all the time in a for loop. What I would like to have are sequential TIFF images. So if the file name would be "Image", I would like the result to be Image0, Image1, Image2 and so forth when I run my For loop. Can anyone help me with this?
    Thanks

    Use the "Format Into String" and the "Build Path" functions:
    Message Edited by smercurio_fc on 06-26-2007 05:16 PM
    Attachments:
    Example_BD.png ‏3 KB

  • Relative path for HTML file

    Hi ,
    This is my requirement. In the ESS Personal information overview page, I can add a HTML file to the additional information section.
    I have created a HTML file by creating a web module and enterprise application and deployed the same through NWDI.
    I declare a resource wher ei mention the path. Here i specifed the complete path of the html file ... like
    http://hostname:portname/addinfo/addinfo.html.  Which i know is a wrong thing to do since when i move the html filel to the production system it will still be accessing the html file in the dev system.
    How do i give the relative path here so that the html file accessed is from the production system when we  go-live.
    Please suggest.
    regards
    sam

    Hi,
    One simpler solution is to use an AppIntegrator iView, as explained in the weblog <a href="https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2786">Integrating your Web Front-ends into the SAP Enterprise Portal using the Application Integrator</a>. It worked well for us.
    You can remove the user authentication part in the portalapp.xml if you don't need it.
    Regards,
    Martin

  • Relative Path for Attach menu forms or icon file

    How should i able to provide relative path while
    attaching Forms,menu or icon files in the Form application.
    So that it can be easily portable
    Thanx in advance
    Upendra

    You can use Regedit and do it manually. I am not sure but it seems to me that using Software Packager for deploying application can also change registry environment variables.

  • How to create a relative path for Flash video on a CDROM

    Hello - I need to distribute a web site to a client on a
    cross-platform Hybrid CDROM so that they can edit and make
    adjustments. This website also includes 2 flash videos that need to
    be included on the CDROM.
    My problem is this: I encoded the video in the Flash Encoder
    app and brought them into the main Flash app for conversion into
    swf files. I also used the media controller parameter to add a
    control skin to the movies. I now have 2 swf files associated with
    the flv video file, and I understand that all 3 of these must stay
    together for the video to work properly. The video plays correctly
    along with the controller skin on my Mac however only the
    controller shows up but no video on the CDROM. I believe that this
    has something to do with absolute vs. relative file paths for the
    video flv file to the swf controller file.
    I do not know how to change this path - I know "where" to
    change it within the controller parameter options box but do not
    know what syntax exactly to place here. How do you specify a
    relative path here? When I try to do it I get an error saying that
    the flv file cannot be found.
    I am trying to use the following syntax: /video/welding.flv
    where video is the name of the folder and welding is the name of
    the file. I have done numerous Google searches on this subject and
    stil cannot find an answer, so any help is appreciated.

    OK - I assigned the FLVPlayback component the instance name
    of videoPlayer to keep it simple. And I copied the above code into
    an Actions - Frame on Frame 1. FYI - The name of the video has been
    changed from welding to Timet Sponge.
    Now I get the following error messages:
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 1: 1119:
    Access of possibly undefined property contentPath through a
    reference with static type fl.video:FLVPlayback.
    videoPlayer.contentPath = "";
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 2: 1120:
    Access of undefined property _global.
    _global.videoURI = "video/Timet Sponge.flv";
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 3: 1120:
    Access of undefined property _global.
    videoPlayer.contentPath = _global.videoURI;
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 3: 1119:
    Access of possibly undefined property contentPath through a
    reference with static type fl.video:FLVPlayback.
    videoPlayer.contentPath = _global.videoURI;
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 1: 1119:
    Access of possibly undefined property contentPath through a
    reference with static type fl.video:FLVPlayback.
    videoPlayer.contentPath = "";
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 2: 1120:
    Access of undefined property _global.
    _global.videoURI = "video/Timet Sponge.flv";
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 3: 1120:
    Access of undefined property _global.
    videoPlayer.contentPath = _global.videoURI;
    **Error** Scene 1, Layer 'Layer 1', Frame 1, Line 3: 1119:
    Access of possibly undefined property contentPath through a
    reference with static type fl.video:FLVPlayback.
    videoPlayer.contentPath = _global.videoURI;
    Total ActionScript Errors: 4, Reported Errors: 4

  • Relative paths of servlets and JSPs

              I am trying to deploy my application in Weblogic 6.0 sp2.
              I have put my JSPs and servlets in a WAR file.
              I have mapped one of the servlets to "GuiController" in the web.xml file.
              I assume that this means if any part of my URL has "GuiController" this servlet
              would be invoked.
              In the JSP (which is in the same WAR file) I would like to specify this servlet
              as the form action.
              as follows :
              <form name="test" method="get" action="GuiController">
              I would like to give the relative path so that I don't have to hard code the web
              app name. But this does not work.
              It works if I specify :
              <form name="test" method="get" action="/edcs/GuiController">
              where edcs is my web app name
              Any suggestions on how I can achieve this without hardcoding the web app name
              Thanks
              Pratima
              

    You have to deploy the web application as the default web application for
              the server. The console is broken in this regard so you have to edit the
              config.xml by hand.
              Peace,
              Cameron Purdy
              Tangosol Inc.
              << Tangosol Server: How Weblogic applications are customized >>
              << Download now from http://www.tangosol.com/download.jsp >>
              "Pratima Nambiar" <[email protected]> wrote in message
              news:[email protected]...
              >
              > I am trying to deploy my application in Weblogic 6.0 sp2.
              > I have put my JSPs and servlets in a WAR file.
              > I have mapped one of the servlets to "GuiController" in the web.xml file.
              > I assume that this means if any part of my URL has "GuiController" this
              servlet
              > would be invoked.
              > In the JSP (which is in the same WAR file) I would like to specify this
              servlet
              > as the form action.
              > as follows :
              > <form name="test" method="get" action="GuiController">
              >
              > I would like to give the relative path so that I don't have to hard code
              the web
              > app name. But this does not work.
              > It works if I specify :
              >
              > <form name="test" method="get" action="/edcs/GuiController">
              > where edcs is my web app name
              >
              > Any suggestions on how I can achieve this without hardcoding the web app
              name
              > ?
              >
              > Thanks
              > Pratima
              >
              >
              >
              

  • Relative path for images in RTF templates

    Hi everybody!
    When I insert an image in a RTF template, I put its path into the web dialog, in order to see correctly the picture when I open the report from the xmlp server, in this way: url:{"http://servername/analytics/res/Images/image.bmp"}
    How can I make this path relative, in order to see the images even if the server name changes?
    Thanks so!
    Francesco

    Hi Tim,
    I am using BIP 10.1.3.3.2. I am able to access system variable CURRENT_SERVER URL.
    Steps:
    <?param@begin:CURRENT_SERVER_URL?>
    <xsl:value-of select="$ CURRENT_SERVER_URL"/>
    CURRENT_SERVER_URL is getting printed in BI Publisher. Value displayed is http://xx4697.xxx.co.in:9704/xmlpserver.
    Now we are importing xsl into RTF template. File aaa.xsl is stored at [BIP_Installation_Directory\oc4j_bi\j2ee\home\default-web-app]
    We have hardcoded the path for XSL in RTF. The path is <?import: http://xx4697.xxx.co.in:9704/aaa.xsl?>
    As we want to set dynamic path we changed hardcoded xsl path to <?import: {$CURRENT_SERVER_URL}/../aaa.xsl?> but it is not working. Sometimes BIP is taking local path of MyDocuments folder and sometimes Desktop path. If I put that XSL file in MyDocuments folder or Desktop, it is working fine. But ideally it should refer [BIP_Installation_Directory\oc4j_bi\j2ee\home\default-web-app] path...
    Thanks,
    Amit D

Maybe you are looking for