15

I'm having trouble launching tomcat on my linux server. I run startup.sh, and get the Tomcat Started logging, but then can't access anything on localhost:8080.

$CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE:   /home/tomcat/apache-tomcat-8.5.11
Using CATALINA_HOME:   /home/tomcat/apache-tomcat-8.5.11
Using CATALINA_TMPDIR: /home/tomcat/apache-tomcat-8.5.11/temp
Using JRE_HOME:        /home/tomcat/jdk1.8.0_121
Using CLASSPATH:       /home/tomcat/apache-tomcat-8.5.11/bin/bootstrap.jar:/home                                                                                        /tomcat/apache-tomcat-8.5.11/bin/tomcat-juli.jar
Tomcat started.

Checking the logs/catalina.out file, there are the following lines in there, but I haven't been able to find any information about these errors.

/home/tomcat/jdk1.8.0_121/bin/java: 1: /home/tomcat/jdk1.8.0_121/bin/java: ^?ELF^A^A^A^B^C^A: not found
/home/tomcat/jdk1.8.0_121/bin/java: 2: /home/tomcat/jdk1.8.0_121/bin/java: Syntax error: "(" unexpected

Any ideas?

mrbengi
  • 3,184
  • 11
  • 45
  • 79
leedsunited92
  • 542
  • 5
  • 12
  • 3
    can you do `file /home/tomcat/jdk1.8.0_121/bin/java`. Looks like your Java binaries are either not suitable for your platform, or corrupt. – geert3 Feb 06 '17 at 21:29
  • 1
    @geert3 , I concur. On my Intel system, the header of ELF files is not (once ASCII-ed) `^?ELF^A^A^A^B^C` - haven't checked the ELF format for its significance, but I suspect they're for a different platform. The question should perhaps be updated with the platform details. – LSerni Feb 08 '17 at 08:23
  • 3
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Feb 10 '17 at 15:32
  • As suggested by others, it could be due to the binaries from a different platform or perhaps something to do with shell script parsing. To isolate. can you get back whether you are able to execute the following command : `$ /home/tomcat/jdk1.8.0_121/bin/java -version` ? – Ravindra HV Feb 10 '17 at 16:25
  • Can you try and check the following things and report back. - Did you check the java binaries which you downloaded are Linux ones ? Please also ensure the correct architecture. - Did some program overwrite those binaries. Check the modification time. - Is the binary a partial download ? – bsd Feb 09 '17 at 03:39

1 Answers1

8

Update

I've decoded the ELF header from your error message: ^?ELF^A^A^A^B^C^A

It is a bunch of caret encoded control characters, which can be decoded as follows:

First 4 bytes are a magic number, identifying the file as an ELF executable.

0x7f (^?) - ELFMAG0 
0x45 (E)  - ELFMAG1
0x4c (L)  - ELFMAG2
0x46 (F)  - ELFMAG3

Next 3 bytes specify the architecture, the endianness and the ELF format version:

0x01 (^A) - ELFCLASS32  (i.e. this is a 32 bit binary)
0x01 (^A) - ELFDATA2LSB (Little Endian)
0x01 (^A) - EI_VERSION  (Version of ELF format EV_CURRENT/1)

So basically it is a 32-bit Java binary.

Then, I've downloaded the 32-bit version of JRE (jre1.8.0_121), and tried to run java with dash, to confirm my shell issue theory (below), and it does indeed produce exactly the same error message you have:

%dash ./java|&less
./java: 1: ./java: ^?ELF^A^A^A^B^C^A: not found
./java: 2: ./java: Syntax error: "(" unexpected

So, most probably, you are using a 32-bit version of Java (as bundled with your Tomcat), on a machine, which is not capable (or configured) to run 32-bit executables. And a shell issue (as described below), then masks the underlying problem, which is why you get this weird looking error message.

It is hard to say more without having a bit more details on your system, so output of uname -a and cat /etc/lsb-release would be nice to have.


...

My bet is that this might be a shell issue, i.e. your /bin/sh points to something like dash, which might cause some compatibility issues with catalina.sh script, and make it interpret bin/java as a script, instead of running it as an executable, under certain circumstances.

In particular older versions of dash are known to executes binary data as a shell script in case of ENOEXEC (i.e. corrupted and/or invalid architecture binary) (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=816313;msg=5).

And your error message

/home/tomcat/jdk1.8.0_121/bin/java: 2: /home/tomcat/jdk1.8.0_121/bin/java: Syntax error: "(" unexpected

looks very much like it.

You can check what your /bin/sh points to, like that:

>ls -l /bin/sh
/bin/sh -> bash

If it is not bash, then modify the shebang line in your /home/tomcat/apache-tomcat-8.5.11/bin/catalina.sh as follows:

#!/bin/bash

and see if it helps, or at least produces a more readable error message.

In case bash fails with cannot execute binary file, check if your java binary is not corrupted and can be executed on your system, by running it by hand:

/home/tomcat/jdk1.8.0_121/bin/java
zeppelin
  • 8,011
  • 1
  • 20
  • 27