?
安装 gradle
Linux & MacOS users
Configure your?PATH?environment variable to include the?bin?directory of the unzipped distribution, e.g.:
$ export PATH=$PATH:/opt/gradle/gradle-5.3/bin
?
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-5.3-bin.zip
$ ls /opt/gradle/gradle-5.3
?
?
git clone https://github.com/jcoleman/tomcat-redis-session-manager.git
?
[root@oldboy tomcat-redis-session-manager]# cat build.gradle
?
tomcat 版本 7.0.78
?
jdk版本 1.8
[root@oldboy ~]# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
?
apply plugin: ‘java‘
apply plugin: ‘maven‘
apply plugin: ‘signing‘
?
group = ‘com.orangefunction‘
version = ‘2.0.0‘
?
repositories {
mavenCentral()
}
?
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
?
dependencies {
compile group: ‘org.apache.tomcat‘, name: ‘tomcat-catalina‘, version: ‘7.0.78‘
compile group: ‘redis.clients‘, name: ‘jedis‘, version: ‘2.5.2‘
compile group: ‘org.apache.commons‘, name: ‘commons-pool2‘, version: ‘2.6.0‘
//compile group: ‘commons-codec‘, name: ‘commons-codec‘, version: ‘1.9‘
?
testCompile group: ‘junit‘, name: ‘junit‘, version: ‘4.+‘
testCompile ‘org.hamcrest:hamcrest-core:1.3‘
testCompile ‘org.hamcrest:hamcrest-library:1.3‘
testCompile ‘org.mockito:mockito-all:1.9.5‘
testCompile group: ‘org.apache.tomcat‘, name: ‘tomcat-coyote‘, version: ‘7.0.78‘
}
?
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = ‘javadoc‘
from ‘build/docs/javadoc‘
}
?
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = ‘sources‘
}
?
artifacts {
archives jar
?
archives javadocJar
archives sourcesJar
}
?
//signing {
// sign configurations.archives
//}
task copyJars(type: Copy) {
from configurations.runtime
into ‘dist‘
}
?
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
?
// repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
// }
//repository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
//}
?
pom.project {
name ‘tomcat-redis-session-manager‘
packaging ‘jar‘
description ‘Tomcat Redis Session Manager is a Tomcat extension to store sessions in Redis‘
url ‘https://github.com/jcoleman/tomcat-redis-session-manager‘
?
issueManagement {
url ‘https://github.com:jcoleman/tomcat-redis-session-manager/issues‘
system ‘GitHub Issues‘
}
?
scm {
url ‘https://github.com:jcoleman/tomcat-redis-session-manager‘
connection ‘scm:git:git://github.com/jcoleman/tomcat-redis-session-manager.git‘
developerConnection ‘scm:git:git@github.com:jcoleman/tomcat-redis-session-manager.git‘
}
?
licenses {
license {
name ‘MIT‘
url ‘http://opensource.org/licenses/MIT‘
distribution ‘repo‘
}
}
?
developers {
developer {
id ‘jcoleman‘
name ‘James Coleman‘
email ‘jtc331@gmail.com‘
url ‘https://github.com/jcoleman‘
}
}
}
}
}
}
?
[root@oldboy tomcat-redis-session-manager]# gradle build -x test copyJars
?
在tomcat-redis-session-manager/build/libs/目录下生成以下几个包
?
在tomcat-redis-session-manager/dist/下生成以下几个包
?
复制3个文件到tomcat/lib目录下
[root@oldboy dist]# cp jedis-2.5.2.jar tomcat-redis-session-manager-2.0.0.jar commons-pool2-2.6.0.jar /usr/local/tomcat/lib/
?
编写tomcat context.xml文件添加redis信息
[root@oldboy ~]# vim /usr/local/tomcat/conf/context.xml
<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
?
http://www.apache.org/licenses/LICENSE-2.0
?
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
?
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
?
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
?
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="10.0.0.51"
port="6379"
password=‘123‘
database="0"
maxInactiveInterval="60" />
</Context>
?
?
?
?
?
[root@oldboy dist]# cat /usr/local/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<body>
<h1><font color="red">TomcatA.linuxinfo.top</font></h1>
<tablealign="centre" border="1">
<tr>
<td>SessionID</td>
<% session.setAttribute("linuxinfo.top","linuxinfo.top");%>
<td><%=session.getId() %></td>
</tr>
<tr>
<td>Createdon</td>
<td><%=session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>
?
6、分别启动tomcat
catalina.sh start #可也用全路径/usr/local/tomcat/bin/startup.sh
7、访问192.168.2.197,测试如下,查看session ID
?
?
?
1下载五个jar包,将jar包放在/usr/local/tomcat/lib:
mget javolution-5.4.3.1.jar
memcached-session-manager-1.8.0jar
memcached-session-manager-tc7-1.8.0.jar
msm-javolution-serializer-1.8.0.jar
spymemcached-1.8.0.jar
?
?
?
?
原文:https://www.cnblogs.com/john5yang/p/10575887.html