在一台电脑上跑两个tomcat的做法:
一、把tomcat放到不同的目录下
二、为避免端口占用冲突,把其中一台的端口8080改成别的,例如8085
三、配置tomcat环境变量CATALINA_BASE和CATALINA_HOME
四、两个tomcat的环境变量如果相同会互相影响,可以给第二个tomcat环境变量配成其他名字,例如CATALINA_BASE2和CATALINA_HOME2
五、需要修改第二个tomcat的bin目录和config目录下所有CATALINA_BASE和CATALINA_HOME的地方。
这个改起来太麻烦,跑个程序就改了。
public class ModifyFilesByContent {
public static void main(String[] args) {
File dir = new File("d:\\user\\01106378\\桌面\\apache-tomcat-7.0.69");
findFileList(dir);
}
private static void findFileList(File dir) {
if(dir==null || dir.isFile()){
return;
}
for (File file : dir.listFiles()) {
if(file.isDirectory()){
if(file.getName().equals("bin") || file.getName().equals("conf")){
findFileList(file);
}
}else{
File distFile = new File(file.getAbsolutePath()+".bak");
try {
BufferedReader in = new BufferedReader(new FileReader(file));
BufferedWriter out = new BufferedWriter(new FileWriter(distFile));
String s = null;
while ((s = in.readLine()) != null) {
if(s.contains("CATALINA_HOME")){
s = s.replace("CATALINA_HOME", "CATALINA_HOME5");
}
if(s.contains("CATALINA_BASE")){
s = s.replace("CATALINA_BASE", "CATALINA_BASE5");
}
out.write(s+"\n");
//out.newLine();
}
out.flush();
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
file.delete();
distFile.renameTo(file);
}
}
}
}