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