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