Re: default directory for files in tomcat
I don't see how an applet would have anything to do with where Tomcat starts up as they aren't even in the same JVM's. Did you mean servlet? Are you counting on being able to read files in a servlet via File IO? Bad, bad, bad, bad, etc Never, ever, use File IO in a servlet application unless you are using paths provided explicitly via deployment configuration or using the servlet container's temp dir. I would even try to avoid using the deployment config if at all possible. Use URL's and Streams to load files using the classloader or the servlet context. As far as your current issue, relatives paths are relative to wherever the JVM started from. If you use the CATALINA_HOME/bin startup files, the VM base path will be set to that directory. If you start it via a service and don't set the base directory for the VM, then it will start from whatever the default base directory is. For instance on WinXP or Win2k, this would probably be C:\winnt\system32. Jake At 01:07 PM 1/22/2004 +, you wrote: I have an applet which requires a .ini file to be loaded up. This file is only found if I am in the directory containing it when I startup tomcat. Is there a default location for files, or is there a config for this? I tried placing them in a few places but none worked unless I started tomcat from within that directory. Thanks Allan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: default directory for files in tomcat
Howdy, The default location for files is the current working directory which is the directory from which the startup script is launched. Needless to say, relying on this is fragile at best. So you want to write your applet such that the location of the .ini file is a parameter, and pass your applet this parameter (preferably a URL obtained via ServletContext#getResource as opposed to a file IO mechanism). Yoav Shapira Millennium ChemInformatics -Original Message- From: Allan Bruce [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 8:08 AM To: [EMAIL PROTECTED] Subject: default directory for files in tomcat I have an applet which requires a .ini file to be loaded up. This file is only found if I am in the directory containing it when I startup tomcat. Is there a default location for files, or is there a config for this? I tried placing them in a few places but none worked unless I started tomcat from within that directory. Thanks Allan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: default directory for files in tomcat
I assume you mean web application, not applet. An alternative is for the webapp to read the file from somewhere on the classpath. I have not tried it and don't know the exact technique, but you should be able to find how to do it. Then you could put your file in web-inf/classes in your .war file. -Original Message- From: ext Shapira, Yoav [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 7:52 AM To: Tomcat Users List Subject: RE: default directory for files in tomcat Howdy, The default location for files is the current working directory which is the directory from which the startup script is launched. Needless to say, relying on this is fragile at best. So you want to write your applet such that the location of the .ini file is a parameter, and pass your applet this parameter (preferably a URL obtained via ServletContext#getResource as opposed to a file IO mechanism). Yoav Shapira Millennium ChemInformatics -Original Message- From: Allan Bruce [mailto:[EMAIL PROTECTED] Sent: Thursday, January 22, 2004 8:08 AM To: [EMAIL PROTECTED] Subject: default directory for files in tomcat I have an applet which requires a .ini file to be loaded up. This file is only found if I am in the directory containing it when I startup tomcat. Is there a default location for files, or is there a config for this? I tried placing them in a few places but none worked unless I started tomcat from within that directory. Thanks Allan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: default directory for files in tomcat
Howdy, An alternative is for the webapp to read the file from somewhere on the classpath. I have not tried it and don't know the exact technique, but you should be able to find how to do it. Then you could put your file in web-inf/classes in your .war file. The technique is simple: place file, e.g. x.prop, in top-level of a jar file on the classpath. Then in any class do URL xProp = getClass().getResource(/x.prop); Or InputStream xPropInput = getClass().getResourceAsStream(/x.prop); Alternatively, you can place the file at the same level as the class that's going to use it and call URL xProp = getClass().getResource(getClass().getPackage().getName() + .x.prop) or the InputStream equivalent. Note no leading slash here. More documentation is at the ClassLoader#getResource javadoc. This is a good technique for anyone to know. Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: default directory for files in tomcat
In the Servlet init() method you can call a method called getRealPath() This will return the name of the directory where your webapp is deployed. You may need to store this is a system property or a static classs for future use as it's only availalble on startup. Donie -Original Message- From: Allan Bruce [mailto:[EMAIL PROTECTED] Sent: 22 January 2004 13:08 To: [EMAIL PROTECTED] Subject: default directory for files in tomcat I have an applet which requires a .ini file to be loaded up. This file is only found if I am in the directory containing it when I startup tomcat. Is there a default location for files, or is there a config for this? I tried placing them in a few places but none worked unless I started tomcat from within that directory. Thanks Allan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. ** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: default directory for files in tomcat
Howdy, In the Servlet init() method you can call a method called getRealPath() This will return the name of the directory where your webapp is deployed. You may need to store this is a system property or a static classs for future use as it's only availalble on startup. This is one of those posts that puts me on edge ;) (Long-time observers of this list know what I mean ;)) The getRealPath method is available during the servlet's entire lifecycle, not just during the init method. The getRealPath method does not work when running a packed WAR file (it returns null by definition). Servlet containers are required to support webapps running as a packed WAR, and not required to support other webapp distributions (e.g. exploded/filesystem). Therefore, by relying on the getRealPath method you compromise the portability of your webapp. It's one thing to follow bad design/development practices yourself -- it's your code, your app, do whatever you want. But please don't share these practices as advice ;) Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]