Hi Jacob,
1.) 1.000 thanks - this was the answer I needed. Do you know where this is to be found in the docs??? I spent quite some time with searching this forum and the internet, but didn't find any recommendation like that you just gave me.
Not positive where it is in the docs, but you might check under the Host, Context, or deployment documentation. I believe it is there, I just don't remember where.
2.) I see context.getAttribute("javax.servlet.context.tempdir") returns the directory the application is living at.
No, you misunderstand. the tempdir is *not* the directory that the application is living at. It works out to something like...
CATALINA_HOME/work/Standalone/localhost/myapp
CATALINA_HOME/work/Standalone/[your virtual host]/[your application context name]
this is very specifically *not* where WEB-INF directory is. If you see one there, it is only because Tomcat is caching information. It is not the context's home.
Is it ok to access the file system using ========= String mydir = (String)context.getAttribute("javax.servlet.context.tempdir"); FileInputStream fin = new FileInputStream(mydir + "/WEB-INF/myconfig.txt"); ========= ? or is it more preferable to use ========= Class myclass = this; FileInputStream fin = (FileInputStream)myclass.getResourceAsStream("WEB-INF/myconfig.txt"); ========= ?
pls give me a hint which type of access is more portable? Do you also know a howto how to create portable web-applications?
Well, the first case is completely incorrect. If your config file happens to be there because Tomcat is doing some sort of caching or something in the app's tempdir, consider it a happy accident. The second case won't work because you are using the classloader to find the resource and "WEB-INF" is not a directory that is in the classpath (although WEB-INF/classes is and so are jars within WEB-INF/lib). Here is how you would do it...
InputStream is = getServletContext().getResourceAsStream("/WEB-INF/myconfig.txt");
using the ServletContext, you can find resources anywhere inside your webapp whether the app is being deployed from a directory or directly from a .war file.
Jake
thx a lot Johannes
Jacob Kjome <[EMAIL PROTECTED]> 28.03.2003 20:27 Please respond to "Tomcat Users List" <[EMAIL PROTECTED]>
To "Tomcat Users List" <[EMAIL PROTECTED]> cc
Subject Re: Living without a Context - deploying an application using manager app
What do you mean "Living without a Context"?
Do you mean "living without a Tomcat <Context ...> entry"?
All you have to do is add META-INF/context.xml (the name "context.xml" is important so don't name it something else) to your .war file. context.xml
is the context configuration file for the context and contains a single <Context ...> element and any nested elements that the <Context ...> element supports.
A sample context.xml might look like...
<Context path="/arbitraypath" docBase="dbadmin.war"/>
Note that the "path" can be anything you want, but the docBase must be the
name of the .war file.
I also saw your other message where you said....
<quote> additionaly, an application deployed using the manager app currently returns null if you use servletcontext.getRealPath(); so it's context seems to be quite obfuscated... </quote>
This is to be expected. When you deploy your app as a .war file and not a
directory structure, you have no file system access. If you are counting of having File IO access to within your webapp, you are creating a non-portable application. The servlet spec does not guarantee any direct file system access to any resource on the server other than the directory path returned by context.getAttribute("javax.servlet.context.tempdir").
there you go.
Jake
At 07:46 PM 3/28/2003 +0100, you wrote:
>hi there,
>
>here are my findings after some experimentation with the ant deploy task
>of the manager app.
>
>*) a complete application can be easily built into a WAR file using ant
>*) this WAR file can be easily deployed using ant deploy task
>*) once deployed onto the server, the application is running with the
>docbase located somewhere under the manager directory:
>ant list
>-> produces:
>"/dbadmin:running:1:F:\tomcat-4.1.18\work\Standalone\localhost\manager\db admin.war"
>
>*) there the application is living
>- without a context
>- thus, also without any JNDI resources etc. defined in server.xml for a
>context dbadmin with docbase dbadmin.
>
>Would renaming the docbase to "
>F:\tomcat-4.1.18\work\Standalone\localhost\manager\dbadmin.war" resolve
>the problem of not having any context?
>What else could be done to get a context for the webapplication
"dbadmin"?
>
>thx
>Johannes