Setup tomcat7
is easy. Just do
sudo apt-get install tomcat7
and http://localhost:8080/
will work already. The default source files are in /usr/share/tomcat7
, while the default path is in /var/lib/tomcat7/webapps/ROOT
.
First install those five packages from Help > Install New Software... > (Work with) Luna > Web, XML, Java EE and OSGi Enterprise development
.
Eclipse Java EE Developer Tools
Eclipse Java Web Developer Tools
Eclipse Web Developer Tools
JST Server Adapters
JST Server Adapters Extensions
Goes to Windows > Performances > Server > Runtime Environment
and add the one just installed, with Tomcat installation directory
as /usr/share/tomcat7
. It is also possible to install a local version of tomcat7
using download and install
and specify folder path; however, what is installed is just identical duplications and there's not much differences.
Goes to File > New > Others > Server > server
and add a new Tomcat v7.0 server, choose the server runtime environment
we just set up. If we setup/remove several times, sometimes it happens that the Server Name
is blank, and there's no way to type anything in it. It is a known bug in Eclipse. Just do
cd ~/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/
rm org.eclipse.jst.server.tomcat.core.prefs
rm org.eclipse.wst.server.core.prefs
then everything is reset.
The Java EE
(rather than Java
) prospective is needed to be switched to.
Change the privacy policy of /usr/share/tomcat7
so Eclipse (and other normal users) can use it.
cd /usr/share/tomcat7
sudo ln -s /var/lib/tomcat7/conf conf
sudo ln -s /etc/tomcat7/policy.d/03catalina.policy conf/catalina.policy
sudo ln -s /var/log/tomcat7 log
sudo chmod -R 777 /usr/share/tomcat7/conf
Copy all files in /usr/share/tomcat7/conf
(inside folders seems unnecessary because they are backups) to ~/workspace/Servers/Tomcat v7.0 Server at localhost-config
. Then either stop the original Tomcat by
sudo service tomcat7 stop
sudo update-rc.d tomcat7 disable
Or choose another port for the Ecplise instance (I am choosing this way) by changing 8080
to 8181
(or whatever unused port) and 8005
to 8115
in ~/workspace/Servers/Tomcat v7.0 Server at localhost-config/server.xml
.
The Servers
view can be shown from Windows > Show View > Others > Servers
, and right now it should be started successfully. Right now http://localhost:8181/
will gives 404 errors.
Just use File > New > Others > Web > Dynamical Web Project
wizard to start a new servlet project. Put whatever servlet code into /src
folder by adding File > New > Others > Web > Servlet
class. Eclipse is complaining import errors. Go to project Properties > Java Build Path > Libraries > Add External Jars...
and add all the things in /usr/share/tomcat7/lib
in it. Then Run on Server
will work, and the page can be viewed from http://localhost:8181/project_name/ClassName
.