Project

General

Profile

Installing Java and Tomcat » History » Version 1

Aleksander Bešir, 07.12.2010 13:02

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
17
    openjdk-6-jdk            install
18
    openjdk-6-jre            install
19
    ...
20
</pre>
21
22
If that command has no results, you’ll want to install the latest version with this command:
23
24
<pre>
25
    sudo apt-get install openjdk-6-jdk
26
</pre>
27
28
h2. Apache Tomcat installation
29
30
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.
31
<pre>
32
33
    wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.14.tar.gz
34
35
    tar xvzf apache-tomcat-6.0.29.tar.gz
36
</pre>
37
38
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.
39
40
<pre>
41
    sudo mv apache-tomcat-6.0.29 /usr/local/tomcat
42
</pre>
43
44
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.
45
46
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.
47
48
<pre>
49
    vi ~/.bashrc
50
</pre>
51
52
Add the following line:
53
54
<pre>
55
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
56
</pre>
57
58
At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.
59
60
h2. Automatic Starting
61
62
To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.
63
64
<pre>
65
    sudo vi /etc/init.d/tomcat
66
</pre>
67
68
Now paste in the following:
69
70
<pre>
71
    # Tomcat auto-start
72
    #
73
    # description: Auto-starts tomcat
74
    # processname: tomcat
75
    # pidfile: /var/run/tomcat.pid
76
77
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
78
79
    case $1 in
80
    start)
81
            sh /usr/local/tomcat/bin/startup.sh
82
            ;;
83
    stop)  
84
            sh /usr/local/tomcat/bin/shutdown.sh
85
            ;;
86
    restart)
87
            sh /usr/local/tomcat/bin/shutdown.sh
88
            sh /usr/local/tomcat/bin/startup.sh
89
            ;;
90
    esac   
91
    exit 0
92
</pre>
93
94
You’ll need to make the script executable by running the chmod command:
95
96
<pre>
97
    sudo chmod 755 /etc/init.d/tomcat
98
</pre>
99
100
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.
101
102
<pre>
103
    sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
104
    sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
105
</pre>
106
107
Tomcat should now be fully installed and operational.