Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tomcat deploy war without losing session

I am working on java web application deployment. I have requirement like we will be keep on deploying new versions of war file in tomcat app. My requirement is when a user is logged in and when I deploy a new war in tomcat web app it overrides old war and I loose session.

I should show user new version without loosing his session.

When I googled I came to know about tomcat parallel deployment. But my manager is asking no to follow that solution and asking to see any other solution is available. But I did not get any other solution.

Is there any way in tomcat to store sessions?

How about other servers like jboss, weblogic or websphere?

like image 422
user2451997 Avatar asked Jan 14 '15 08:01

user2451997


People also ask

What happens when we deploy a WAR file in Tomcat?

Java web applications are usually packaged as WAR files for deployment. These files can be created on the command line or with an IDE, like Eclipse. After deploying the WAR file, Tomcat unpacks it and stores all the project files from the webapps directory in a new directory named after the project.

Can we deploy WAR file in Tomcat?

Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.

What is hot deployment in Tomcat?

To remedy this situation, Tomcat provides a number of "hot deployment" options, which simply means that any deployments, redeployments, and adjustments to applications are made while the server is still running, rather than requiring it to stop. There are a number of ways to use hot deployment with Tomcat.

What is auto deployment in Tomcat?

Tomcat auto-deploy issuesxml file in the conf directory of the installation. After this has been set, deployment can be achieved by simply moving a WAR file into the remote Tomcat webapps directory via some file transfer means (FTP, SCP etc.).


2 Answers

As mentioned by Gas, see http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts

Configure <Manager> with some explicit path name. By default the sessions are stored in the work directory of a web application. The work directory is deleted when a web application is undeployed.

If you configure the pathname attribute explicitly to point to some directory that is not deleted on undeployment, the sessions will survive.

Note that you can use ${catalina.base} and other system properties in your configuration.

like image 149
Konstantin Kolinko Avatar answered Oct 03 '22 10:10

Konstantin Kolinko


Are you familiar with Redis? It is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.

Using the Redisson java client, you can configure the RedissonSessionManager, which persists all of Tomcat’s session data in Redis.

This way, if you restart your Tomcat instance it will recover the session from Redis once it is started.

This approach has the additional advantage, of being a very convenient way to share your session data between different Tomcat instances, allowing you to cluster them behind a Load Balancer without session stickiness (like nginx).

You can read more about configuring tomcat with the RedissonSessionManager here:

https://dzone.com/articles/redis-based-tomcat-session-management

Good luck!

like image 21
A. Beristain Avatar answered Oct 03 '22 11:10

A. Beristain