How to install Tomcat7 in Ubuntu 14.04 LTS?
Solution 1
I believe your CATALINA_BASE is incorrect it runs out of the /var/lib/tomcat7 directory and CATALINA_HOME is proper in regards to how you have declared the variable. Add CATALINA_HOME and CATALINA_BASE to /etc/default/tomcat7 along with JAVA_HOME and JRE_HOME. That executable notifies the tomcat servlet of how the environment is set upon start up of the servlet.
It could also be considered to put them in /etc/profile and then export them in /etc/bash.bashrc (i.e. export CATALINA_HOME). This should only be done if and only if your site doesn't have user login or registration. With out exporting the variables they would still be declared locally.
To globally declare the variables an approach, if you are the admin (group 4, you might also want to think about moving syslog to group 37, purging rsyslog and just keep the daemon running for logs as well so you preserve mandatory access control) you could ponder creating a ~/.bash_completion or ~/.bash_expert file in your home directory where you have something like this:
# ~/.bash_expert in regards to servlet alias
if [ -f /etc/bash_completion.d/.tomservlet ]; then
. /etc/bash_completion.d/.tomservlet
fi
export CATALINA_HOME
export CATALINA_BASE
export JRE_HOME
export JAVA_HOME
Then create the .tomservlet file in /etc/bash_completion.d/.tomservlet and add the following:
CATALINA_HOME=/usr/share/tomcat7
CATALINA_BASE=/var/lib/tomcat7
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
JRE_HOME=$JAVA_HOME:/jre
Once that is completed add the following lines to ~/.bashrc
if [ -f "$HOME/.bash_expert" ];then
. "$HOME/.bash_expert"
fi
Then source the ~/.bashrc file as shown below:
:~$ source .bashrc
and that should take care of your problems, in a secure fashion no matter what type of client side interaction is taken place. (Don't hold me to that, you never know what martians are lurking in cyberspace, it can be a scary realm sometimes).
P.S. I previously was referring to the oracle-sun jdk7 or I guess its just Oracle Jdk7 so if you are using the Open Jdk replace it as necessary, if using the oracle go back into the /etc/init.d/tomcat file and change openjdk to your version where the script refers to "$OPENJDK". This also assumes you installed from the repositories.
Good luck, and may your tomcat purr!!
Solution 2
I tried this on a fresh container:
sudo apt-get install tomcat7
sudo dpkg-reconfigure tomcat7
It seems to fix the issue in my case.
Edit : dpkg-reconfigure will replace your custom config for tomcat7 with the default packet manager configuration, or, where given, it will present a menu to customize.
Solution 3
Download the official tomcat from their website
wget http://mirrors.fe.up.pt/pub/apache/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.zip
Decompress it
unzip apache-tomcat-7.0.54.zip
Make sure you have Java installed and JAVA_HOME defined
Start your tomcat.
Related videos on Youtube
Juan Garcia
Updated on September 18, 2022Comments
-
Juan Garcia over 1 year
If I
apt-get install tomcat7
it is installing a broken tomcat7. A simple startup.sh will give me errors, than when fixed says that tomcat has started but nothing shows up in localhost:8080. shutdown.sh will give me errors and even throw Java exceptions. This wasn't happening in some previous Ubuntu release, where it simply worked. So, it is looks like tomcat package it been not maintained lately.I can get it working from Eclipse (which by the way it is not been properly maintain too) when I am testing my web app. However there are things I need to test in an standalone tomcat installation. So far, Google hasn't helped.
Have any of you managed to properly installing tomcat7 in Ubuntu 14.4LTS? If so, can you point me to the right direction?
Edit:
Here is some logs.
Starting tomcat:
$ sudo /usr/share/tomcat7/bin/startup.sh Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar Tomcat started.
Browsing to
localhost:8080
(andhttp://127.0.0.1:8080
,http://127.0.0.1
,http://[my network ip here]
):Oops! Google Chrome could not connect to localhost:8080
Stopping tomcat also fails:
$ sudo /usr/share/tomcat7/bin/shutdown.sh Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.ClassLoaderFactory validateFile WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], isDirectory: [false], canRead: [false] Jul 03, 2014 7:15:55 PM org.apache.catalina.startup.Catalina stopServer SEVERE: Catalina.stop: java.io.FileNotFoundException: /usr/share/tomcat7/conf/server.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:466) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:370) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:457)
-
Juan Garcia almost 10 yearsThe
$ sudo service tomcat7 restart
output istomcat7: unrecognized service
-
hwez almost 10 years$ cd /opt/local/tomcat7/bin $ ls you will find shell script file im not exactly sure about the name it could be restart.sh excute it by $ sudo sh restart.sh if the restart.sh dont exist try to start then close then start again by $ sudo startup.sh $ sudo shutdown.sh $ sudo startup.sh
-
Juan Garcia almost 10 years/opt/local/tomcat7/bin doesn't exist, it is under /usr/share/tomcat7/bin. startup.sh said that tomcat has started but the browser can't see anythin in localhost:8080 (trying with local ip too). shutdown.sh show warnings and throws an exception. I will update the question with the log
-
Juan Garcia almost 10 yearsUpdate: I have posted my logs
-
hwez almost 10 years/opt/tomcat/bin or /opt/tomcat7 or /etc/tomcat7 or /etc/tomcat if you dont find it cd /opt; ls -lh && cd /etc; ls -ls put in pastebin & comment it im going to install tocat7 & check it for u
-
Juan Garcia almost 10 yearsNothing under /etc or /opt. Under /usr/share/tomcat* is tomcat7, tomcat7-admin, tomcat7-docs, tomcat7-examples, tomcat7-root
-
Juan Garcia almost 10 yearsLooking my logs make me thing that even when the default CATALINA_BASE and CATALINA_HOME are pointing to the same path, one of them might be incorrect. Correct me if I am wrong.
-
hwez almost 10 yearsthe problem is this file is missing /usr/share/tomcat7/conf/server.xml (No such file or directory) just restart the service by & this is how to configure the tomcat7 with apche2 diegobenna.blogspot.com/2011/01/…
-
Ashwani Kumar Rahul over 8 yearswhat to do if localhost:8080 works fine but server_IP_address:8080 does not.... will the above procedure work.....
-
John Little almost 8 yearsTried this, didnt fix the error for me sadly. Broke my install also, bind exceptions etc.
-
user283885 almost 8 yearsShould have added that reconfigure replaces any custom files with the package manager's defaults for the given package.