Tomcat 7 和 Java 8 在树莓派上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27617158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:43:11  来源:igfitidea点击:

Tomcat 7 with Java 8 on Raspberry Pi

javatomcat7raspbian

提问by col.panic

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

UPDATEtomcat8 似乎在这种情况下工作,因为我可以根据需要打开 /manager/ 页面。虽然这不能解决这里的原始问题状态,但我建议您在这种情况下使用 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 examplesshould work. This, however, is not the case as the manager page leaves me with the following error:

根据tomcat7 不编译 jsp 示例应该可以工作。但是,情况并非如此,因为管理器页面给我留下了以下错误:

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?

有谁知道这里的实际问题可能是什么?

回答by Marcel Korpel

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):

正如问题中所述,Raspbian 提供的 Tomcat 不适用于 Java 8。我按照此博客上的说明设法安装了 Tomcat 8 。为了避免链接错误并纠正一个小错误,我将几乎按字面意思引用那里的文本(针对 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 "" 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: 
$ sudo update-rc.d tomcat defaults
{start|stop}" exit 1 ;; esac

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

$ sudo /etc/init.d/tomcat start

Test that the tomcat server starts:

$ sudo /etc/init.d/tomcat stop

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

Tomcat screenshot

Test that the tomcat server stops:

$ sudo apt-get update

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

在树莓派上安装 Apache Tomcat 8

在我的 Raspberry Pi 上,我已经安装了 Apache 2 HTTP 服务器,因此本文对 Tomcat 进行了基本的安装和配置。首先,更新所有已安装的软件包:

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)

确认 Java 已经安装:

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

登录pi用户的主目录并下载所需的Tomcat版本:

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

提取压缩的 tarball:

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

添加以下用户 XML 元素作为 tomcat-users 父元素的最后一个子元素 ~/apache-tomcat-8.0.24/conf/tomcat-users.xml(这将创建一个名为“system”的管理员帐户,其密码为“raspberry”):

#!/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 "" 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: 
$ sudo update-rc.d tomcat defaults
{start|stop}" exit 1 ;; esac

更改以下目录的目录权限,因为默认情况下,pi Linux 用户无法写入它们:

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

在/etc/init.d目录下添加一个名为tomcat的启动脚本,内容如下:

$ sudo /etc/init.d/tomcat start

使用 update-rc.d 命令将适当的链接添加到 /etc/rc?.d 目录:

$ sudo /etc/init.d/tomcat stop

测试tomcat服务器是否启动:

##代码##

在 Web 客户端上,将浏览器指向 http://”Raspberry Pi IP Address”:8080

雄猫截图

测试tomcat服务器是否停止:

##代码##

最后,重新启动系统,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,在用户的主目录中安装软件,但它有效。

回答by sagar khamkar

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/