Tomcat 7 JDBC Session Persistence

as root run:

export CATALINA_OPTS=”-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

create table in mysql:

createtabletomcat_sessions (
  session_id     varchar(100) notnullprimarykey,
  valid_session  char(1) notnull,
  max_inactive   intnotnull,
  last_access    bigintnotnull,
  app_name       varchar(255),
  session_data   mediumblob,
cd /usr/share/java
cd /usr/share/tomcat7/lib and run:
/usr/share/tomcat7/lib# ln -s ../../java/mysql-connector.jar mysql-connector.jar
in META-INF create context.xml
paste Manager section:
<Context antiJARLocking="true" >
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        searchVirtualFirst="true" />

    <Manager className="org.apache.catalina.session.PersistentManager"
        <Store className="org.apache.catalina.session.JDBCStore"
               sessionValidCol="valid_session" />

Run two projects on one tomcat in intellij idea

I have two web application in one project configured using pom. i want to run both the application simultaneously using same instance of Tomcat

Solution is:

Go to Run -> Edit configuration
* add a new configuration for your project (give it a jazzy name)
* Select your Application server( in your case tomcat {version} )
* on the server tab -> before launch section -> add build command for both your artifacts
* go to deployment tab -> add both your application war for deployment
* make sure you provide distinct application context (option on the right)
* Select you new configuration for your project
* click on that green play button .

Tomcat remote debuging

В начало нужно добавить:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

в конец (добавлено jpda):
exec “$PRGDIR”/”$EXECUTABLE” jpda start “$@”

В среде разработки нужно указать хост и порт(в данном случае 8000)

sha1 java

package main;



public class HashTextTest {


* @param args

* @throws NoSuchAlgorithmException


public static void main(String[] args) throws NoSuchAlgorithmException {

System.out.println(sha1(“test string to sha1”));


static String sha1(String input) throws NoSuchAlgorithmException {

MessageDigest mDigest = MessageDigest.getInstance(“SHA1”);

byte[] result = mDigest.digest(input.getBytes());

StringBuffer sb = new StringBuffer();

for (int i = 0; i < result.length; i++) {

sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));


return sb.toString();



remove java in ubuntu

Remove all the Java related packages (Sun, Oracle, OpenJDK, IcedTea plugins, GIJ):

sudo apt-get update
apt-cache search java | awk ‘{print($1)}’ | grep -E -e ‘^(ia32-)?(sun|oracle)-java’ -e ‘^openjdk-‘ -e ‘^icedtea’ -e ‘^(default|gcj)-j(re|dk)’ -e ‘^gcj-(.*)-j(re|dk)’ -e ‘java-common’ | xargs sudo apt-get -y remove
sudo apt-get -y autoremove
Purge config files:

dpkg -l | grep ^rc | awk ‘{print($2)}’ | xargs sudo apt-get -y purge
Remove Java config and cache directory:

sudo bash -c ‘ls -d /home/*/.java’ | xargs sudo rm -rf
Remove manually installed JVMs:

sudo rm -rf /usr/lib/jvm/*
Remove Java entries, if there is still any, from the alternatives:

for g in ControlPanel java java_vm javaws jcontrol jexec keytool orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc; do sudo update-alternatives –remove-all $g; done
Search for possible remaining Java directories:

sudo updatedb
sudo locate -b ‘\pack200’
If the command above produces any output like /path/to/jre1.6.0_34/bin/pack200 remove the directory that is parent of bin, like this: sudo rm -rf /path/to/jre1.6.0_34.