简体   繁体   English

Tomcat 7 和 Java 8 在树莓派上

[英]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. UPDATE tomcat8 似乎在这种情况下工作,因为我可以根据需要打开 /manager/ 页面。 While this does not solve the original problem state here I advise you to use tomcat8 from debian backports in this scenario!虽然这不能解决这里的原始问题状态,但我建议您在这种情况下使用 debian backports 中的 tomcat8!

Raspbian delivers the current Java 8 in version Raspbian 提供当前的 Java 8 版本

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安装 tomcat 7 后,我恢复到 debian backports 提供的 tomcat7 版本,它是

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.根据tomcat7 不编译 jsp 示例应该可以工作。 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 .如问题所述,Raspbian 提供的 Tomcat 不适用于 Java 8。我设法按照此博客上的说明安装了 Tomcat 8。 To avoid linkrot and correct a small mistake, I'll quote the text there almost literally (updated for version 8.0.24):为了避免链接错误并纠正一个小错误,我将几乎按字面意思引用那里的文本(针对 8.0.24 版进行了更新):

Installing Apache Tomcat 8 on a Raspberry Pi在树莓派上安装 Apache Tomcat 8

On my Raspberry Pi I have already installed Apache 2 HTTP server and hence this article does a basic install and configuration of Tomcat.在我的 Raspberry Pi 上,我已经安装了 Apache 2 HTTP 服务器,因此本文对 Tomcat 进行了基本的安装和配置。 Firstly, update all installed packages:首先,更新所有已安装的软件包:

 $ sudo apt-get update

Confirm that Java is already installed:确认 Java 已经安装:

 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:登录pi用户的主目录并下载所需的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:提取压缩的 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”):添加以下用户 XML 元素作为~/apache-tomcat-8.0.24/conf/tomcat-users.xml的 tomcat-users 父元素的最后一个子元素(这将创建一个名为“system”的管理员帐户,其密码为“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:更改以下目录的目录权限,因为默认情况下,pi Linux 用户无法写入它们:

[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 ] [注意:我不必执行此步骤,因为在 8.0.24 版本中,没有目录apache-tomcat-8.0.24/work/Catalina ]

Add a startup script called tomcat to the /etc/init.d directory, which has the following contents:在/etc/init.d目录下添加一个名为tomcat的启动脚本,内容如下:

 #!/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:使用 update-rc.d 命令将适当的链接添加到 /etc/rc?.d 目录:

 $ sudo update-rc.d tomcat defaults

Test that the tomcat server starts:测试tomcat服务器是否启动:

 $ sudo /etc/init.d/tomcat start

On a web client, point your browser at http://”Raspberry Pi IP Address”:8080在 Web 客户端上,将浏览器指向http://”Raspberry Pi IP Address”:8080

雄猫截图

Test that the tomcat server stops:测试tomcat服务器是否停止:

 $ 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.最后,重新启动系统,Tomcat 应用程序服务器现在应该会在启动时自动启动,在系统关闭时也是如此。

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.需要指出的一件事:对我来说,作为一个铁杆 Linux 用户,这个解决方案听起来有点 hacky,在用户的主目录中安装软件,但它有效。

Steps to install Apache tomcat new version on raspberry pi:在树莓派上安装 Apache tomcat 新版本的步骤:

1)sudo apt-get update 1)sudo apt-get 更新

2)sudo apt-get install default-jdk 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 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 4)sudo apt-get install 解压

5)sudo unzip apache-tomcat-8.5.47.zip 5)sudo 解压 apache-tomcat-8.5.47.zip

6)cd apache-tomcat-8.5.47/bin/ 6)cd apache-tomcat-8.5.47/bin/

7)sudo chmod 700 *.sh 7) 须藤 chmod 700 *.sh

8)sudo ./startup.sh 8) 须藤 ./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.如果您收到 404 错误,或者如果您想在端口 80 上安装 apache tomcat,请访问以下链接以了解如何执行此操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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