Setup Memo: Tomcat 7 on eclipse

tomcat-bk-header
Following commands get Tomcat

sudo apt-get update
sudo apt-get install tomcat7

While installing I was being asked

Creating config file /etc/logrotate.d/tomcat7 with new version
 * no JDK or JRE found - please set JAVA_HOME
invoke-rc.d: initscript tomcat7, action "start" failed.

I tried run this command to prepare JAVA_HOME, then I got this message:

$ vim ~/.bashrc

Now I need to install “vim” by following error message:
“The program ‘vim’ can be found in the following packages…”

sudo apt-get install vim

After installing vim, open the file, and go to the last line by press ‘G’ key, then press ‘i’ to be edit mode, and add following, then press ‘esc’ key to exit the edit mode, then save it and close it by type ‘:wq’

JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

Check the result:

$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin
$ readlink -f /usr/bin/javac
/usr/lib/jvm/java-8-oracle/bin/javac

Run this command to edit tomcat config file

sudo nano /etc/default/tomcat7

OR for Lubuntu

sudo leafpad /etc/default/tomcat7

I replaced “JAVA_HOME” and “JAVA_OPTS”

JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC"
JAVA_HOME=/usr/lib/jvm/java-8-oracle

Run tomcat:

sudo service tomcat7 restart

Then go this http://127.0.0.1:8080. It worked!
tomcat-worked

sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples

Some additional installation.

Check the tomcat installed:

$ whereis tomcat7
tomcat7: /etc/tomcat7 /usr/share/tomcat7

Need to give permissions for Tomcat:

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
sudo ln -s /var/lib/tomcat7/common common
sudo ln -s /var/lib/tomcat7/server server
sudo ln -s /var/lib/tomcat7/shared shared

Adding the Tomcat as eclipse server:
Window -> Pereferemces -> Server -> Runtime Environments -> Add
2016-01-08-214109_eclipse_tomcat
Enter the Tomcat installed directory and specify the JRE, then hit “Finish”
2016-01-08-214827_eclipse1
Tomcat had been added as a eclipse server.

To disable autostart for a service

sudo update-rc.d tomcat7 disable

To open config file:

nobu@HP15z:/etc/init.d$ sudo leafpad tomcat7

Selection_005
Tomcat can be started manually via eclipse server

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.