前言
从Ubuntu源安装tomcat7之后遇到了各种奇葩问题,特别是配置eclipse的时候,都TM快崩溃了。哥也是折腾了两年服务器的人,整整搞了一天才让eclipse正常的运行tomcat,记录一下配置的过程,因为已经搞定而且已然被搞晕,中间可能会有各种遗漏,大家有问题跟帖询问吧(ps:我现在都还不清楚tomcat到底是干神马用的)
环境
ubuntu12.04 desktop + tomcat7 + Eclipse java EE IDE for Web Developers
Ubuntu源
既然选择了Ubuntu,最好采用Ubunut自带的apt-get安装方式,虽然后面配置有很多蛋疼的地方,但是这里依然选择从Ubuntu源安装
安装Tomcat
-
sudo apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin
sudo apt-get install tomcat7 tomcat7-docs tomcat7-examples tomcat7-admin
tomcat占用了8080端口,但是我这个端口分给了nginx,因此需要修改端口设置:
-
vim /etc/tomcat7/server.xml
vim /etc/tomcat7/server.xml
将8080修改为7071,打开浏览器访问,成功安装tomcat7应该显示:
弊端
Ubuntu默认安装Tomcat,将Tomcat的各种配置分配到了不同的目录,可以使用dpkg -L tomcat7 查看tomcat的安装目录,如图所示:
-
/.
-
/var
-
/var/log
-
/var/log/tomcat7
-
/var/lib
-
/var/lib/tomcat7
-
/var/lib/tomcat7/webapps
-
/var/lib/tomcat7/common
-
/var/lib/tomcat7/common/classes
-
/var/lib/tomcat7/server
-
/var/lib/tomcat7/server/classes
-
/var/lib/tomcat7/shared
-
/var/lib/tomcat7/shared/classes
-
/var/cache
-
/var/cache/tomcat7
-
/etc
-
/etc/tomcat7
-
/etc/tomcat7/Catalina
-
/etc/tomcat7/Catalina/localhost
-
/etc/tomcat7/catalina.properties
-
/etc/tomcat7/logging.properties
-
/etc/tomcat7/context.xml
-
/etc/tomcat7/server.xml
-
/etc/tomcat7/tomcat-users.xml
-
/etc/tomcat7/web.xml
-
/etc/tomcat7/policy.d
-
/etc/tomcat7/policy.d/01system.policy
-
/etc/tomcat7/policy.d/02debian.policy
-
/etc/tomcat7/policy.d/03catalina.policy
-
/etc/tomcat7/policy.d/04webapps.policy
-
/etc/tomcat7/policy.d/50local.policy
-
/etc/logrotate.d
-
/etc/logrotate.d/tomcat7
-
/etc/init.d
-
/etc/init.d/tomcat7
-
/etc/cron.daily
-
/etc/cron.daily/tomcat7
-
/usr
-
/usr/share
-
/usr/share/doc
-
/usr/share/doc/tomcat7
-
/usr/share/doc/tomcat7/copyright
-
/usr/share/tomcat7-root
-
/usr/share/tomcat7-root/default_root
-
/usr/share/tomcat7-root/default_root/META-INF
-
/usr/share/tomcat7-root/default_root/META-INF/context.xml
-
/usr/share/tomcat7-root/default_root/index.html
-
/usr/share/tomcat7
-
/usr/share/tomcat7/defaults.template
-
/usr/share/tomcat7/defaults.md5sum
-
/var/lib/tomcat7/logs
-
/var/lib/tomcat7/work
-
/var/lib/tomcat7/conf
-
/usr/share/doc/tomcat7/README.Debian.gz
-
/usr/share/doc/tomcat7/changelog.Debian.gz
/.
/var
/var/log
/var/log/tomcat7
/var/lib
/var/lib/tomcat7
/var/lib/tomcat7/webapps
/var/lib/tomcat7/common
/var/lib/tomcat7/common/classes
/var/lib/tomcat7/server
/var/lib/tomcat7/server/classes
/var/lib/tomcat7/shared
/var/lib/tomcat7/shared/classes
/var/cache
/var/cache/tomcat7
/etc
/etc/tomcat7
/etc/tomcat7/Catalina
/etc/tomcat7/Catalina/localhost
/etc/tomcat7/catalina.properties
/etc/tomcat7/logging.properties
/etc/tomcat7/context.xml
/etc/tomcat7/server.xml
/etc/tomcat7/tomcat-users.xml
/etc/tomcat7/web.xml
/etc/tomcat7/policy.d
/etc/tomcat7/policy.d/01system.policy
/etc/tomcat7/policy.d/02debian.policy
/etc/tomcat7/policy.d/03catalina.policy
/etc/tomcat7/policy.d/04webapps.policy
/etc/tomcat7/policy.d/50local.policy
/etc/logrotate.d
/etc/logrotate.d/tomcat7
/etc/init.d
/etc/init.d/tomcat7
/etc/cron.daily
/etc/cron.daily/tomcat7
/usr
/usr/share
/usr/share/doc
/usr/share/doc/tomcat7
/usr/share/doc/tomcat7/copyright
/usr/share/tomcat7-root
/usr/share/tomcat7-root/default_root
/usr/share/tomcat7-root/default_root/META-INF
/usr/share/tomcat7-root/default_root/META-INF/context.xml
/usr/share/tomcat7-root/default_root/index.html
/usr/share/tomcat7
/usr/share/tomcat7/defaults.template
/usr/share/tomcat7/defaults.md5sum
/var/lib/tomcat7/logs
/var/lib/tomcat7/work
/var/lib/tomcat7/conf
/usr/share/doc/tomcat7/README.Debian.gz
/usr/share/doc/tomcat7/changelog.Debian.gz
这种安装方式会导致Eclipse无法识别Tomcat,因此需要通过软链接将很多文件整合到/usr/share/tomcat7目录下,命令如下:
-
sudo ln -s /var/lib/tomcat7/conf /usr/share/tomcat7/conf
-
sudo ln -s /etc/tomcat7/policy.d/03catalina.policy /usr/share/tomcat7/conf/catalina.policy
-
sudo ln -s /var/log/tomcat7 /usr/share/tomcat7/logs
-
sudo chmod -R 777 /usr/share/tomcat7/conf
sudo ln -s /var/lib/tomcat7/conf /usr/share/tomcat7/conf
sudo ln -s /etc/tomcat7/policy.d/03catalina.policy /usr/share/tomcat7/conf/catalina.policy
sudo ln -s /var/log/tomcat7 /usr/share/tomcat7/logs
sudo chmod -R 777 /usr/share/tomcat7/conf
(ps:这里注意,tomcat6需要log目录,而tomcat7需要的是logs目录,我也是后来才发现的)
启动tomcat
可以查看脚本是否有错误(logs目录的错误就是我启动这个脚本发现的)
关闭tomcat
禁止开机启动
因为需要让eclipse运行tomcat,开机自启动会导致端口被占用,因此需要禁止tomcat的开机自启动
-
update-rc.d -f tomcat7 remove
update-rc.d -f tomcat7 remove
配置Eclipse
ok,开始Eclipse的各种Tomcat配置,具体参考了Stackoverflow各种回答,反正按照我这个配置顺序一般问题就不大了
tomcat插件
1、下载tomcat插件,进入官网 http://www.eclipsetotale.com/tomcatPlugin.html 下载对应的插件
2、解压文件,将解压的文件夹复制到eclipse->plugins下。此时若打开eclipse,会发现菜单栏出现了三个服务器小猫的图案
3、打开eclipse,在Window->Preferences->Tomcat,配置如图所示即可:
Server配置
1、解决“Cannot create a server using the selected type”问题 :
-
cd ~/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/
-
rm org.eclipse.jst.server.tomcat.core.prefs
-
rm org.eclipse.wst.server.core.prefs
cd ~/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/
rm org.eclipse.jst.server.tomcat.core.prefs
rm org.eclipse.wst.server.core.prefs
restart Eclipse
2、增加一个新的server
Window->Preferences->Server,如图所示:
选择 Add
选择Next:
Finish即可
web项目
构建一个dynamic web project,run on server即可
(责任编辑:IT) |