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

How to setup eclipse in Linux

eclipse-header
My environment is Lubuntu 14.04

nobu@nobu-HP-Notebook:~$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
nobu@nobu-HP-Notebook:~$ readlink -f $(which java)
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
nobu@nobu-HP-Notebook:~$ 

After doing some reserch, OpenJDK is not as good as “regular” JDK for eclipse
So, I tried to download “regular” JDK 8

nobu@nobu-HP-Notebook:~$ sudo add-apt-repository ppa:webupd8team/java

After running this command, I realized that I should remove OpenJDK

nobu@nobu-HP-Notebook:~$ java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (IcedTea 2.6.3) (7u91-2.6.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
nobu@nobu-HP-Notebook:~$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/java-8-oracle/jre/bin/java          1         manual mode

Press enter to keep the current choice[*], or type selection number: 2   
update-alternatives: using /usr/lib/jvm/java-8-oracle/jre/bin/java to provide /usr/bin/java (java) in manual mode

Then I remove the OpenJDK as follow:

nobu@nobu-HP-Notebook:~$ sudo apt-get purge openjdk*

Now removed:

nobu@nobu-HP-Notebook:~$ sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         manual mode

And run following commands

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

Let’s see how it’s been installed

nobu@nobu-HP-Notebook:~$ readlink -f $(which java)
/usr/lib/jvm/java-8-oracle/jre/bin/java
nobu@nobu-HP-Notebook:~/Downloads$ java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

Downloading eclipse:
Eclipse has been download under Home\Downlolads foloder, and extract .gz file

Run this commands to move eclipse folder under opt directory:

$ cd ~/Downloads

1. Move to the folder where eclipse has downloaded

$ sudo tar -zxvf eclipse-jee-mars-1-linux-gtk-x86_64.tar.gz -C /opt

2. extract and copy the eclipse under opt directory
Note: -zxvf is extracting command for “.gz” archive file

$ gksudo gedit /usr/share/applications/eclipse.desktop

3. After the eclipse has been created, open this file and paste the below info:
Note: “gedit” is not for Lubuntu since Ubuntu uses GNOME, but Lubuntu is LXDE.

$ sudo leafpad /usr/share/applications/eclipse.desktop

Therefore, needs to use leafpad instead of gedit.

[Desktop Entry]
Name=Eclipse 4
Type=Application
Exec=/opt/eclipse/eclipse
Terminal=false
Icon=/opt/eclipse/icon.xpm
Comment=Integrated Development Environment
NoDisplay=false
Categories=Development;IDE;
Name[en]=Eclipse

eclipse-workbench-launch
The eclipse launch with default work space