I have a webapp deployed in a Tomcat7 in webapps/webapp. Inside this webapp there a logback.xml and persistence.property files.
When I start the server this files are taken into consideration. I'd like tomcat to load this files from an external directory. e.g. /home/tomcat/conf
How do I do that?
You can use VirtualWebappLoader to load logback.xml and persistence.property from an external directory.
The configuration looks like this:
<Context ...>
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/tomcat/conf" />
</Context>
Hope this helps.
Related
I have to deploy my app.war file in tomcat 7. The .war file name is followed by its version no.
Here I need to set up a context path, so that the actual url will contain only the app name(without version no).
My requirement is that, there should be no edit in server.xml.
My context.xml is as follows.
<?xml version='1.0' encoding='utf-8'?>
<Context path="/app" docBase="app-1.0" debug="0" reloadable="true">
<!-- Defines links to JNDI Data Sources -->
<!-- Thus the server determines database connection. -->
<ResourceLink
name="..."
global="..."
auth="Container" type="javax.sql.DataSource"/>
.....
.....
</Context>
The context.xml is placed inside the war at /META-INF folder.
Can anyone tell me where am i wrong.
All the elements are in the docs :
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
For your use case, you could do try :
change your version number format (from app-1.0.0.war to app##1.0.0.war
for instance)
place your war in another folder and create a app.xml
in $catalina.base/conf/Catalina/ which contains : <Context path="/app" docBase="/path/to/app-1.0" debug="0" reloadable="true">
avoid having your war with version number
Had a similar problem and it took me a long time to find the solution. It's on the tomcat site but it's difficult to find. This is what I did.
Your war file will be deployed to a folder under %CATALINA_BASE%. I put mine in a folder called deploy. (%CATALINA_BASE%/deploy)
You'll create an XML file with the path to your war file above and place it in %CATALINA_BASE%/conf/Catalina/localhost. The name of the xml file will become your context root. If the name of your war file is app1.2.war and you want your context root to be /app you're create app.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="C:\tomcat7\Servers\server-app\deploy\app1.2" reloadable="false"/>
(My deployment is on Windows, you'll obviously have to adjust for a different OS.)
Also, let's for whatever reason say you want your context root to be /foo/Bar/app, change the name of your xml to foo#Bar#app.xml.
I have a Tomcat 7 Server in Eclipse with two webapps a and b and need to find out how to have application specific configuration files for tomcat that works with Eclipse.
Now I want for each webapp a custom config file, like described here: Apache Tomcat: multiple webapps. So I created a <TomcatDirectory>/conf/Catalina/localhost folder and put the a.xml and b.xml there. This works fine when I run Tomcat from command line.
But where have I to put the application specific configuration files a.xml and b.xml when I run Tomcat from within eclipse?
I already tried to put the files in Eclipse in <EclipseWorkspace>\Servers\<ServerName>\conf\Catalina\localhost\ but WTP does not copy this files to <EclipseWorkspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost
Leave them in <TomcatDirectory>/conf/Catalina/localhost
Server > Open > Server Locations
Change from:
Use workspace metadata
To:
Use Tomcat instalation
Now a.xml and b.xml from <TomcatDirectory>/conf/Catalina/localhost will be used.
If it's for development's purpose, you can specify a folder into the "docBase" attribute of context file like this :
<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true" docBase="C:/devel/MyApp/web/target/MyApp-web" path="/MyApp" reloadable="true">
<Resource
... />
</Context>
By adding these context files directly into /conf/Catalina/localhost, everything is configured and should work like you want but you'll have to stop the tomcat server every time you'll want to clean and build your project.
What you are looking for is to have context.xml files for two different applications.create context.xml file under web application's (a and b) META-INF folder and you should be able to run both the application with their own context.xml file. In eclipse you should be able to create META-INF folder for your respective web applications in parallel to WEB-INF directory
I would like to have an additional classpath directory in tomcat 7, like what can be done by adding ${catalina.home}/mydir in catalina.properties, but specific to an application (war).
I would also like this setting to be outside the war (I found this SO question, but the configuration is within the war).
I my case, it is to have two environments (say integration and QA) on the same container, with different configurations. I wish to keep the artifacts environment agnostic, so not changing the path to the configuration files (properties, logback, ...).
Can this be done ? How ?
Thank you.
VirtualWebappLoader https://stackoverflow.com/a/6410589/173149:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/websandbox">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
virtualClasspath="/usr/.../*.jar;/usr/.../*.jar"/>
</Context>
This config can be placed in $CATALINF_ROOT/config/Catalina/localhost/$PREFIX.xml where $PREFIXis context of your application. Use ROOT to place at /
I have a problem. I created a web app and packaged it with "Ldap" name. Then I put it into tomcat webapps directory. When I enter localhost:8080/Ldap in a browser, it works fine. But I want to start this web app when writing localhost:8080. How can I do this in Tomcat. Is there any Tomcat configuration to supply this. Thanks
You need to provide a context.xml file with your webapp, containing a Context element with an empty attribute path. This is explained in the tomcat configuration reference.
<Context path="" ...>
...
</Context>
This context.xml file should be located under /META-INF/ in your web application (not /WEB-INF/).
I copy-paste-deployed a webapp to a local installation of Tomcat 6 (I place "my-app" folder under "webapps"). I expected my app to be accessible via http://localhost:8080/my-app/.
Instead, I find that it is accessible directly via the root path (http://localhost:8080/).
What configuration can be the cause of this?
This is my context.xml (comments stripped)
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
If you're using IntelliJ, the web path to your application is specified in Edit Configuration -> Deployment tab. You can click on an artifact you're deploying and change its web path in Application context dropdown (which is / by default)
Depends what you copied and pasted but take at look at the ROOT.XML file in Tomcat and see whether that's configured to serve the application instead.
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html