9

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 (and http://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)
jasmines
  • 10,643
  • 16
  • 84
  • 108
Juan Garcia
  • 109
  • 1
  • 1
  • 10
  • could you post startup.sh and shutdown.sh output? – Lety Jun 29 '14 at 18:11
  • 5
    What is meant by `apt-get install tomcat7` is installing **broken** tomcat7 ? – Pandya Jun 30 '14 at 06:38
  • 1
    Unfortunately there's not enough details here. What exactly makes you think that Tomcat7 is broken from the repositories? What symptoms suggest this? – Thomas Ward Jul 02 '14 at 00:17
  • Post the error logs. And also: what does 'but nothing shows up in localhost:8080' means? void page? connection error page? 404? – eddieferetro Jul 02 '14 at 08:59
  • 1
    @Pandya by broken I mean that apt-get is installing a not working package. It can be not configured, not updated, incomplete, buggy... – Juan Garcia Jul 03 '14 at 10:53
  • @eddieferetro done – Juan Garcia Jul 03 '14 at 10:53
  • @JuanGarcia what is out-put of `apt-get install tomcat7`? – Pandya Jul 03 '14 at 10:57
  • @Thomas W. I've have added more details. The repositories package is probably not properly configured or is missing files. It didn't happened before. No enough information in Google about tomcat7 on 14.4, what it makes me think that hasn't be properly tested and fixed. That is what I'm trying to find out. If it is a bug I'll report it back to the community, if not this can help to someone having the same issue – Juan Garcia Jul 03 '14 at 11:00
  • I found this [link](https://bugs.launchpad.net/serverguide/+bug/1232258). Check if directory in /usr/share/tomcat7 exists and if not exec: sudo ln -s /var/lib/tomcat7/common/ common sudo ln -s /var/lib/tomcat7/server/ server sudo ln -s /var/lib/tomcat7/shared/ shared . An other problem I see is the value of JRE_HOME, check your $CATALINA_BASE/bin/setenv.sh and sets JRE_HOME to proper path – Lety Jul 03 '14 at 14:25
  • i have updated the the answer with a video – hwez Jul 04 '14 at 01:27
  • First install java by `sudo apt-get install default-jre` & `sudo apt-get install defualt-jdk` and then try to install tomcat7 – αғsнιη Jul 04 '14 at 05:40
  • Bug #1232258: tomcat7 installer fails to create symbolic links https://bugs.launchpad.net/serverguide/+bug/1232258 – DmitrySandalov Nov 04 '14 at 19:32
  • @DmitrySandalov yes, that is how I solved last time, by manually creating the link. I were too busy to answer myself to this question and I felt been unethical to answer when I had offer a bounty, so I waited for someone else. So, please, if you feel like creating a detailed answer of how to make it work you'll get the accepted one. – Juan Garcia Nov 05 '14 at 20:33
  • I had this problem on Docker with Ubuntu 14.04, and this solved it for me: http://stackoverflow.com/questions/29683231/tomcat7-fail-to-start-inside-ubuntu-docker-container?rq=1 – Mathias Conradt Feb 28 '16 at 20:33

6 Answers6

8

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.

user283885
  • 446
  • 2
  • 5
3

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!!

oOpSgEo
  • 541
  • 2
  • 9
2
  1. 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
    
  2. Decompress it

    unzip apache-tomcat-7.0.54.zip       
    
  3. Make sure you have Java installed and JAVA_HOME defined

  4. Start your tomcat.

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
LnxSlck
  • 12,146
  • 1
  • 41
  • 51
0

installing eclipse & defult jdk & git

$ sudo apt-get eclipse
$ sudo apt-get eclipse-jdt
$ sudo apt-get eclipse-pde
$ sudo apt-get eclipse-platform
$ sudo apt-get eclipse-rcp

$ sudo apt-get install default-jdk
$ sudo apt-get install ant git

i'm using ssh because it's a Virtual Machine 'for test'
1 download the file 'tomcat7.0 apache download'

$ wget http://apache.claz.org/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz

2 extract it ls

$ sudo tar -xvf apache-tomcat-7.0.54.tar.gz

3 make dir at

$ sudo mkdir /usr/local/tomcat7

4 move the file to the dir

$ mv apache-tomcat-7.0.54 /usr/local/tomcat7

5 installing

$ cd /usr/local/tomcat7/apache-tomcat-7.0.54
$ sudo ln -s /var/lib/tomcat/conf conf
$ sudo ln -s /etc/tomcat7/policy.d/03catalina.policy/conf/catalina.policy
$ sudo ln -s /var/log/tomcat7 log
$ sudo chmor -R 777 /usr/local/tomcat7/apach*/conf

6 configuration now we go to the ubuntu desktop

Lunch eclipse => window => Preferences => Server => Runtime Envirenment


select the version browse the dir => finish

$ cd ../../apach*/bin
$ ls -la 

shut it down

$ sudo ./shutdown.sh

lets make a test

eclipse => file => new => other... => web project

doulble click it => right click web content => test.htm 

<html>
<head>
<title> testing tomcat7 & eclipse</title>
</head>
<h2>Job's Done !</h2>

click on 'no servers are ....' => tomcat version => next => add to configured 
menu => run => run as => fninish
localhost:8080/test/test.htm
localhost:8080/project name/page name

Video tutorial : 'http://www.youtube.com/watch?v=n5joqK07-NE'

hwez
  • 2,956
  • 1
  • 17
  • 15
  • The `$ sudo service tomcat7 restart` output is `tomcat7: unrecognized service` – Juan Garcia Jul 03 '14 at 09:38
  • $ 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 – hwez Jul 03 '14 at 09:48
  • /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 Jul 03 '14 at 10:10
  • Update: I have posted my logs – Juan Garcia Jul 03 '14 at 10:22
  • /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 – hwez Jul 03 '14 at 10:24
  • Nothing under /etc or /opt. Under /usr/share/tomcat* is tomcat7, tomcat7-admin, tomcat7-docs, tomcat7-examples, tomcat7-root – Juan Garcia Jul 03 '14 at 10:29
  • Looking 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. – Juan Garcia Jul 03 '14 at 10:32
  • I've made a mistake. /etc/tomcat7 exists, and server.xml is in there. But shutdown.sh is trying to read it from /usr/share/tomcat7/conf/server.xml – Juan Garcia Jul 03 '14 at 10:48
  • the 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 http://diegobenna.blogspot.com/2011/01/connect-tomcat-7-with-apache2-modjk-and.html – hwez Jul 03 '14 at 10:58
0

Try launching it like a service with service tomcat7 start.

I've tried and it in my local (ubuntu 14.04) and works. It gave me a problem with de JAVA_HOME, but I've fix this way it and works:

1- Edit tomcat's config file:

vim /etc/default/tomcat7

2- Search JAVA_HOME line (it's commented), and put something like:

JAVA_HOME=/usr/lib/jvm/<your-jvm>

p.e:

JAVA_HOME=/usr/lib/jvm/java-7-oracle

Save and start tomcat like a service:

root@skynet:/etc/init.d# service tomcat7 start
 * Starting Tomcat servlet engine tomcat7  

and

root@skynet:/etc/init.d# service tomcat7 stop
 * Stopping Tomcat servlet engine tomcat7
eddieferetro
  • 288
  • 1
  • 3
  • 10
0

I had no problems installing and running Tomcat 7 in Ubuntu 14.04 LTS. Just to make sure, I looked up the bash history. Note that I first installed Oracle Java (in case it makes a difference)

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

then Tomcat

sudo apt-get install tomcat7

The command

sudo service tomcat7 restart

gives

 * Stopping Tomcat servlet engine tomcat7           [ OK ] 
 * Starting Tomcat servlet engine tomcat7           [ OK ]
atmelino
  • 149
  • 8