Project

General

Profile

Installing Java and Tomcat » History » Version 2

Aleksander Bešir, 07.12.2010 13:03

1 1 Aleksander Bešir
h1. Installing Java and Tomcat
2
3
Some of the following
4
5
h2. JDK installation
6
7
Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so:
8
9
<pre>
10
    dpkg –get-selections | grep openjdk
11
</pre>
12
13
This should give you this output if you already installed java:
14
15
<pre>
16
    openjdk-6-jdk            install
17
    openjdk-6-jre            install
18
    ...
19
</pre>
20
21
If that command has no results, you’ll want to install the latest version with this command:
22
23
<pre>
24
    sudo apt-get install openjdk-6-jdk
25
</pre>
26
27
h2. Apache Tomcat installation
28
29
Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly.
30
<pre>
31
32
    wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.14.tar.gz
33
34
    tar xvzf apache-tomcat-6.0.29.tar.gz
35
</pre>
36
37
The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to.
38
39
<pre>
40
    sudo mv apache-tomcat-6.0.29 /usr/local/tomcat
41
</pre>
42
43
Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.
44
45
The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.
46
47
<pre>
48
    vi ~/.bashrc
49
</pre>
50
51
Add the following line:
52
53
<pre>
54
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
55
</pre>
56
57
At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.
58
59
h2. Automatic Starting
60
61
To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.
62
63
<pre>
64
    sudo vi /etc/init.d/tomcat
65
</pre>
66
67
Now paste in the following:
68
69
<pre>
70
    # Tomcat auto-start
71
    #
72
    # description: Auto-starts tomcat
73
    # processname: tomcat
74
    # pidfile: /var/run/tomcat.pid
75
76
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
77
78
    case $1 in
79
    start)
80
            sh /usr/local/tomcat/bin/startup.sh
81
            ;;
82
    stop)  
83
            sh /usr/local/tomcat/bin/shutdown.sh
84
            ;;
85
    restart)
86
            sh /usr/local/tomcat/bin/shutdown.sh
87
            sh /usr/local/tomcat/bin/startup.sh
88
            ;;
89
    esac   
90
    exit 0
91
</pre>
92
93
You’ll need to make the script executable by running the chmod command:
94
95
<pre>
96
    sudo chmod 755 /etc/init.d/tomcat
97
</pre>
98
99
The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
100
101
<pre>
102
    sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
103
    sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
104
</pre>
105
106
Tomcat should now be fully installed and operational.