简体   繁体   中英

Tomcat 7 with Java 8 on Raspberry Pi

UPDATE tomcat8 seems to work in this scenario as I could open the /manager/ page as required. While this does not solve the original problem state here I advise you to use tomcat8 from debian backports in this scenario!

Raspbian delivers the current Java 8 in version

root@raspberrypi:/etc/apt# java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

after installing tomcat 7 i reverted to the tomcat7 version provided by debian backports which is

root@raspberrypi:/etc/apt# dpkg -l |grep tomcat
ii  libtomcat7-java                       7.0.56-1~bpo70+2                        all          Servlet and JSP engine -- core libraries
ii  tomcat7                               7.0.56-1~bpo70+2                        all          Servlet and JSP engine
ii  tomcat7-admin                         7.0.56-1~bpo70+2                        all          Servlet and JSP engine -- admin web applications
ii  tomcat7-common                        7.0.56-1~bpo70+2                        all          Servlet and JSP engine -- common files

which according to tomcat7 not compiling jsp examples should work. This, however, is not the case as the manager page leaves me with the following error:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: [1] in the generated java file: [/var/lib/tomcat7/work/Catalina/localhost/manager/org/apache/jsp/index_jsp.java]
The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:477)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
    org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)

Does anybody know what the actual problem here could be?

As stated in the question, Tomcat as provided by Raspbian doesn't work with Java 8. I managed to install Tomcat 8 following the instructions on this blog . To avoid linkrot and correct a small mistake, I'll quote the text there almost literally (updated for version 8.0.24):

Installing Apache Tomcat 8 on a Raspberry Pi

On my Raspberry Pi I have already installed Apache 2 HTTP server and hence this article does a basic install and configuration of Tomcat. Firstly, update all installed packages:

 $ sudo apt-get update

Confirm that Java is already installed:

 pi@raspberrypi /usr/bin $ java -version java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

Log in to the home directory for the pi user and download the desired release of Tomcat:

 $ wget http://mirrors.axint.net/apache/tomcat/tomcat-8/v8.0.24/bin/apache-tomcat-8.0.24.tar.gz

Extract the zipped tarball:

 $ tar xvf apache-tomcat-8.0.24.tar.gz

Add the following user XML element as the last child of the tomcat-users parent element of ~/apache-tomcat-8.0.24/conf/tomcat-users.xml (this creates an admin account called “system” who's password is “raspberry”):

 <user username="system" password="raspberry" roles="manager-gui"/>

Change the directory permissions on the following directorys, since by default, the pi Linux user cannot write to them:

[NB: I didn't have to do this step, as in release 8.0.24, there was no directory apache-tomcat-8.0.24/work/Catalina ]

Add a startup script called tomcat to the /etc/init.d directory, which has the following contents:

 #!/bin/sh # /etc/init.d/tomcat # starts the Apache Tomcat service ### BEGIN INIT INFO # Provides: tomcat # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: true # Short-Description: Start/stop tomcat application server ### END INIT INFO export CATALINA_HOME="/home/pi/apache-tomcat-8.0.24" case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" /bin/su pi $CATALINA_HOME/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" /bin/su pi $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac

Use the update-rc.d command to add the appropriate links to the /etc/rc?.d directories:

 $ sudo update-rc.d tomcat defaults

Test that the tomcat server starts:

 $ sudo /etc/init.d/tomcat start

On a web client, point your browser at http://”Raspberry Pi IP Address”:8080

雄猫截图

Test that the tomcat server stops:

 $ sudo /etc/init.d/tomcat stop

Finally, reboot the system and the Tomcat application server should now start automatically on startup, and likewise when the system shuts down.

All credits go to The Friday Night Project.

One thing to point out: to me, as a hardcore Linux user, this solution sounds a bit hacky, installing software in a user's home directory, but it works.

Steps to install Apache tomcat new version on raspberry pi:

1)sudo apt-get update

2)sudo apt-get install default-jdk

3)sudo wget http://mirrors.estointernet.in/apache/tomcat/tomcat-8/v8.5.47/bin/apache-tomcat-8.5.47.zip

4)sudo apt-get install unzip

5)sudo unzip apache-tomcat-8.5.47.zip

6)cd apache-tomcat-8.5.47/bin/

7)sudo chmod 700 *.sh

8)sudo ./startup.sh

In case you are getting a 404 error or if you want to install apache tomcat on port 80 then please visit the below link to know how to do that.

http://www.bytesofgigabytes.com/raspberrypi/install-apache-tomcat-on-raspberry-pi/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM