I just want to know how to make automatic reflect on web application if i make changes in my servlets class file .
Because when ever I make changes in servlets class file I have to do server shutdown and startup
Otherwise go to tomcat web application manager
And reload the web-application
Is there another method which automatic do this
Set <Context reloadable="true" />, Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development. But not in production environment. See the reloadable doc.
Edit:
How to set context
Edit install_dir/conf/server.xml and add a DefaultContext subelement to the main Service element and supply true for the reload able attribute
Add
<DefaultContext reloadable="true"/>
before the
</host>
tag.
Related
I'm using spring mvc and tomcat as a server. I want to be able to change a jndi field that is Autowired(as String):
<jee:jndi-lookup id="someMessage" jndi-name="someMessage"/>
in one of the my services, that is referenced to conf/context.xml of Tomcat, that looks something like this:
<Environment name="someMessage" value="Change this." type="java.lang.String" />.
However, when I change the value on context.xml, this change is not reflected on my service managed by spring, unless I restart server. Is there anyway to reflect this change without restarting or redeploying war? I know there is a solution to include such a dynamic field in one of properties file and then use commons configuration library to reload the changes, but I'm looking for a solution to keep this field on my conf/context.xml...
I think that is not possible. Why don't use a property file or a static class?
As far as I know, it's impossible if you put it into the conf/context.xml of your tomcat home as the following doc shows:
StandardContext.html#reload(): If the context.xml has changed, you should stop this Context and create (and start) a new Context instance instead. -- i.e. can't achieve by original context
Reload Existing App: Reload an existing web application, to reflect changes in the contents of /WEB-INF/classes or /WEB-INF/lib. -- i.e. not reflect the change of context.xml
But you can define your app's /META-INF/context.xml, which will be packed into war and you can replace war without restart server.
When we make a change to form bean in Struts why we need to restart tomcat
and not when we make a change in an action class?
By default when you restart the tomcat then and then only the class loader runs again and the changes effects.
You can change that behavior by configuration of reloadable attribute.
reloadable=true
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected.
I have an app which should save content (user avatars) in some directory, for example C:\avadir. In my app I'm using SpringMVC. I need to show user defined avatars. For this I have to configure Tomcat to use this external directory.
I have such opthions in my ROOT.xml, placed in %CATALINA_HOME%\conf\Catalina\localhost:
<Context path="/ava" docBase="c:/avadir" debug="0" reloadable="true" crossContext="true" />
and next settings in my servlet-context.xml:
<resources mapping="/ava/**" location="/ava/" />
After set up this settings I still can't get access to my file placed in C:\avadir\file.jpg by url localhost:8080/ava/file.jpg.
Is there something missed?
You can achieve what you want without modifying your ROOT.xml file which should make your application slightly more easy to manage.
So firstly I would remove the Context definition from ROOT.xml.
Secondly I would modify your current Spring MVC configuration to serve the images as part of the Spring MVC application. Using the path that you have suggested I would update your <resources> definition to:
<mvc:resources mapping="/ava/**" location="file:///C:/avadir"/>
This is essentially configuring your Spring MVC implementation to serve resources directly from the filesystem rather than relying upon the second context that you have configured in Tomcat.
You also need to remember that the Spring MVC resources mapping will be relative to the context of your web application. For example: if your application is deployed at http://example.com:8080/myApp then the /ava mapping will actually match when accessed with URL http://example.com:8080/myApp/ava/file.jpeg
Is there a way to find out the java classes loaded in the server stack and replace the same with the latest version of the same without restarting the web or application server?
On Tomcat, there is an attribute called reloadable which support automatic reloading of changed classes/libraries. From Tomcat site:
reloadable
"Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. That's why the default setting for this attribute is false. You can use the Manager web application, however, to trigger reloads of deployed applications on demand."
Sample usages is (Add following line in server.xml file):
<Context path="/webdev" docBase="/webdev" reloadable="true"></Context>
for more info, please refer http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
I have a web application project which is deployed in tomcat 6.
I can access my application using the url:
http://localhost:8082/MyApplication
I also wan't to be able to access this application by another url like:
http://localhost:8082/myapp
Is this possible ? if yes what alternatives do i have ?
Off course, I don't want to change the original name of the application('MyApplication').
Thanks,
Abhishek.
If you add the Context within server.xml it will work as you want. Give the path attribute you wish.
<Context docBase="MyApplication" path="/myapp" />
Though it works, this approach is not recommended by the Tomcat docs, since any changes to server.xml means restarting the server disturbing all the web apps.
But, on the flip side, the practice of keeping this in Catalina_Home/conf/Catalina/localhost/context.xml (which is recommended by the docs) has some unreliabilities as others have reported - when you redeploy the war you can lose the context.xml too
See Why-does-tomcat-replace-context-xml-on-redeploy and
Why does tomcat like deleting my context.xml file?