废话不多说,记下来,方便以后查阅
首先,下载tomcat6并解压到指定目录 重命名为tomcat
这时候当我们想启动tomcat的时候会出现如下错误:
deimmatoiMac-5:~ deim$ cd /Users/deim/Documents/work/tomcat/bin
deimmatoiMac-5:bin deim$ sh startup.sh
Cannot find ./catalina.sh
The file is absent or does not have execute permission
This file is needed to run this program
好,既然catalina.sh找不到,那不妨试试 打开 catalina.sh
deimmatoiMac-5:bin deim$ sh catalina.sh
The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program
经过google才知道是catalina.sh找不到JAVA_HOME,好,既然你找不到我就给你配。
JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home;
(该路径可由eclipse中拷贝)
修改好后再次执行 sh catalina.sh还是出现如下提示,这是因为没有执行权限
The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program
那就给所有的sh文件执行权限 chmod +x *.sh
好,再次sh catalina.sh
deimmatoiMac-5:bin deim$ sh catalina.sh
Using CATALINA_BASE: /Users/deim/Documents/work/tomcat
Using CATALINA_HOME: /Users/deim/Documents/work/tomcat
Using CATALINA_TMPDIR: /Users/deim/Documents/work/tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Users/deim/Documents/work/tomcat/bin/bootstrap.jar
Usage: catalina.sh ( commands ... )
commands:
debug Start Catalina in a debugger
debug -security Debug Catalina with a security manager
jpda start Start Catalina under JPDA debugger
run Start Catalina in the current window
run -security Start in the current window with security manager
start Start Catalina in a separate window
start -security Start in a separate window with security manager
stop Stop Catalina, waiting up to 5 seconds for the process to end
stop n Stop Catalina, waiting up to n seconds for the process to end
stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running
version What version of tomcat are you running?
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined
行,那现在就执行下startup.sh试试
deimmatoiMac-5:bin deim$ sh startup.sh
Using CATALINA_BASE: /Users/deim/Documents/work/tomcat
Using CATALINA_HOME: /Users/deim/Documents/work/tomcat
Using CATALINA_TMPDIR: /Users/deim/Documents/work/tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Users/deim/Documents/work/tomcat/bin/bootstrap.jar
oh yeah~跑起来了。第一步完成。
接下来就是部署maven项目到tomcat上了
1.tomcat的tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user password="admin" roles="manager-gui, manager-script" username="admin"/>
2.maven的setting.xml
<pluginGroup>org.codehaus.cargo</pluginGroup>
.......
<server>
<id>tomcat</id>
<username>admin</username>
<password>admin</password>
</server>
3.maven项目的pom.xml
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>admin</cargo.remote.username>
<cargo.remote.password>admin</cargo.remote.password>
<cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url>
</properties>
</configuration>
</configuration>
</plugin>
好了,现在可以 mvn clean install 然后 mvn catgo:redeploy
注意:redeploy前tomcat必须已经启动