how to disable tomcat caching?
I use this -
<Context antiJARLocking="true" antiResourceLocking="true" cachingAllowed="false" cacheMaxSize ="0" cacheTTL="1">
in Tomcat/conf/context.xml
but it not helps
Actual problem is antiResourceLocking="true".
Looks like there is a conflict with cachingAllowed="false".
I'm not sure what you're using, but in context.xml you can change the value of cachingAllowed by removing the flag.
Remember to delete the cache folder after that.
Resources :
Apache Tomcat Configuration Reference
On the same topic :
How do I disable tomcat caching? I'm having weird static file problems.
cachingAllowed did not help. I resolved this by modifying :
$CATALINA_HOME/conf/Catalina/localhost/thewebapp.xml
which is the cached file of context.xml
Put below code in your sever.xml file.
<Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="false"
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true"
reloadable="false"
wrapperClass="org.apache.catalina.core.StandardWrapper">
</Context>
Make sure to delete all data from /work/Catalina/localhost directory before restarting tomcat.
Also clear your browser cache.
Its a good practice to disable browser caching while your app is in development.
This post may help Disabling Chrome cache for website development
Related
I am trying to setup a clustering environment with Wildfly-10.
I have a web-fragment.xml for general purpose configuration and a web.xml for project specific configuration. With these configurations, clustering does not work.
But if I delete web-fragment.xml and move its content to web.xml, everything works fine.
I wonder what is the reason of this. Any idea?
Placing </distributable> tag to both web.xml and web-fragment.xml has solved the problem.
I have installed tomcat with eclipse and I have a project with a servlet. Here I put the structure of both:
Until this day the steps followed to run the servlet were:
1.Press button right above the following and give "Start"
Tomcat
2.Once booted, press right button over "UsuarioServlet.java" / Run as / Run on server
Done that everything worked properly but suddenly today when doing so I get the following:
What happened?.
I had this problem recently.
Here is what helped me.
Start tomcat and search in the console the real path where your tomcat is running.
Go there and open conf/server.xml. The plug-in that integrates tomcat and eclipse adds one long line there. Scroll down to see it. Here is how this line looks on my machine.
<Context docBase="C:\workspaces\work7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\ROOT" path="" reloadable="false"/><Context debug="0" docBase="C:\workspaces\work7\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\webapp" path="/mycompany-webapp-0.9-SNAPSHOT" reloadable="true" source="org.eclipse.jst.jee.server:webapp">
<Valve className="org.apache.catalina.valves.AccessLogValve" pattern="common" prefix="access_log." suffix=".txt"/>
Please pay attention on path attribute. It used to be /webapp but now it became /mycompany-webapp-0.9-SNAPSHOT. So, this is the real URL where the application is deployed.
I used to surf to my application using url http://localhost:8080/webapp.
Now I have to use http://localhost:8080/mycompany-webapp-0.9-SNAPSHOT.
Alternatively I can stop server, fix the path in server.xml manually, start server and use the "old" URL.
The point is that this behavior is not consistent. Sometimes (when project settings are being changed) this problem is fixed "automatically" but sometimes it returns. It happened not only on my machine but on computers of 2 other team members in company where I work.
I hope this information will help you. Good luck.
I'm having trouble with JDBC Connection Pooling, I've done all the same with explained here: JNDI Resources HOW-TO, and here is also question (the same configuration with mine) regarding this topic which has not been resolved, I think.
What else should I consider?
I hope you have done the ResourceLink configuration to your webapp, too.
<Context>
...
<ResourceLink global="jdbc/MyDS" name="jdbc/MyDS" type="javax.sql.DataSource" />
...
</Context>
I had this error when the JDBC driver was deleted from classpath. In my setup, Tomcat expected libraries in a special directory, which was filled by Maven executing a special target. Whenever I cleaned and forgot to execute the Maven's target prior to running Tomcat, I had precisely this error.
For some applications I use ZK, others Hibernate, other Apache Commons, etc.
I don't want to deploy a 75MB war file, just because it uses lots of libraries.
I don't want to add the libraries to my tomcat lib folder, or nor the classpath to it's configuration as I may have an old application using library x.1 and another application using library x.2
For this reason, it would be great to have something in the web.xml or context.xml where I say something like:
<classpath>/usr/local/tomcat/custom-libs/zk-5.0.4</classpath>
Note: The above is pseudo-code
From Tomcat 7 there is no mention of not being able to use the VirtualWebappLoader in production. I tried it and it works like a dream. Simply add the following to META-INF/context.xml:
<?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>
In Netbeans, under packaging, I just untick all the packages, taking the .war size down to nothing, make sure the dependencies are in the correct folders on the server and upload. Yey! No more 100 MB WAR file.
Addition #Spider answer.
Tomcat Context hold Loader element. According to docs deployment descriptor (what in <Context> tag) can be placed in:
$CATALINA_BASE/conf/server.xml - bad - require server restarts in order to reread config
$CATALINA_BASE/conf/context.xml - bad - shared across all applications
$CATALINA_BASE/work/$APP.war:/META-INF/context.xml - bad - require repackaging in order to change config
$CATALINA_BASE/work/[enginename]/[hostname]/$APP/META-INF/context.xml - nice, but see last option!!
$CATALINA_BASE/webapps/$APP/META-INF/context.xml - nice, but see last option!!
$CATALINA_BASE/conf/[enginename]/[hostname]/$APP.xml - best - completely out of application and automatically scanned for changes!!!
Here my config which demonstrate how to use development version of project files out of $CATALINA_BASE hierarchy (note that I place this file into src/test/resources dir and intruct Maven to preprocess ${basedir} placeholders through pom.xml <filtering>true</filtering> so after build in new environment I copy it to $CATALINA_BASE/conf/Catalina/localhost/$APP.xml):
<Context docBase="${basedir}/src/main/webapp"
reloadable="true">
<!-- http://tomcat.apache.org/tomcat-7.0-doc/config/context.html -->
<Resources className="org.apache.naming.resources.VirtualDirContext"
extraResourcePaths="/WEB-INF/classes=${basedir}/target/classes,/WEB-INF/lib=${basedir}/target/${project.build.finalName}/WEB-INF/lib"/>
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
virtualClasspath="${basedir}/target/classes;${basedir}/target/${project.build.finalName}/WEB-INF/lib"/>
<JarScanner scanAllDirectories="true"/>
<!-- Use development version of JS/CSS files. -->
<Parameter name="min" value="dev"/>
<Environment name="app.devel.ldap" value="USER" type="java.lang.String" override="true"/>
<Environment name="app.devel.permitAll" value="true" type="java.lang.String" override="true"/>
</Context>
UPDATE Tomcat 8 change syntax for <Resources> and <Loader> elements, corresponding part now look like:
<Resources>
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
webAppMount="/WEB-INF/classes" base="${basedir}/target/classes" />
<PostResources className="org.apache.catalina.webresources.DirResourceSet"
webAppMount="/WEB-INF/lib" base="${basedir}/target/${project.build.finalName}/WEB-INF/lib" />
</Resources>
Another a bit hacky alternative.
You can write a 5-6 line custom class loader which derives from urlclassloader, and simply adds your classpath jars using addUrl() method.
Then set it as the context class loader of the thread in your application code.
Thread.setContextClassLoader(new CustomClassloader(path, parentClassLoader)
where parent class loader typically is
Thread.getContextClassloader()
This is what the META-INF/context.xml file can be used for. You defined your own WebappLoader, which loads classes for your particular webapp. This is the reference I used: http://tomcat.apache.org/tomcat-5.5-doc/config/loader.html (Edit: for Tomcat 6: http://tomcat.apache.org/tomcat-6.0-doc/config/loader.html, for Tomcat 7: http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html)
Also this fellow here seems to post a solution to your exact problem (example included): http://java.dzone.com/articles/extending-tomcat-webapploader
We are using multiple solr instances on tomcat but want that they log into different log files. How could we do this?
We are using the follwing xml file under tomcat/conf/Catalina/localhost to make it working:
<Context docBase="/pathtosolr/dist/apache-solr-1.4.0.war" debug="0" crossContext="true" >
<Environment name="solr/home" type="java.lang.String" value="/pathtosolr/solr" override="true" />
</Context>
Update: From Jems answer I found this documentation:
Tomcat offers a choice between settings for all applications or settings specifically for the Solr application.
To change logging settings for Solr only, edit tomcat/webapps/solr/WEB-INF/classes/logging.properties. You will need to create the classes directory and the logging.properties file. You can set levels from FINEST to SEVERE for a class or an entire package. Here are a couple of examples:
org.apache.commons.digester.Digester.level = FINEST
org.apache.solr.level = WARNING
Alternately, if you wish to change Tomcat’s JDK Logging API settings for every application in this instance of Tomcat, edit tomcat/conf/logging.properties.
See the documentation for the SLF4J Logging API for more information:
http://slf4j.org/docs.html
You might wanna take a look at this page: http://globalgateway.wordpress.com/2010/01/06/configuring-solr-1-4-logging-with-log4j-in-tomcat/
There seems to be no good solution:
2008 and 2010
except repacking the solr.war file with a different logging configuration file.
Update: see accepted answer!