Linux 有使用 Raspberry PI 的 Java 经验吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12090745/
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
Any Java experience on Raspberry PI?
提问by johnny-b-goode
Is it possible to run average java app server on e.g. jboss or glassfish server on Raspberry pi? Any limitations? Does anyone have an experience in Java development for raspberry pi?
是否可以在树莓派上的 jboss 或 glassfish 服务器上运行普通的 Java 应用服务器?有什么限制吗?有没有人有树莓派的 Java 开发经验?
At least any appropriate JVM for RPi will be nice.
至少任何适用于 RPi 的 JVM 都会很好。
采纳答案by raju-bitter
It's absolutely possible, but should work better with newer versions having more memory (e.g. the 512 MB version of the Pi). In December 2012 Oracle released a Developer Preview of Java SE 8 for ARM. The blog post with the announcement contains links to a number of tutorials which should get you started with plain Java SE or JavaFX, depending on how fancy your interfaces should be.
这绝对是可能的,但应该更适合具有更多内存的新版本(例如 512 MB 版本的 Pi)。2012 年 12 月,Oracle 发布了Java SE 8 for ARM的开发人员预览版。带有公告的博客文章包含许多教程的链接,这些教程应该可以让您开始使用普通的 Java SE 或 JavaFX,具体取决于您的界面应该有多花哨。
If you are concerned about the performance of JavaFX on the Raspberry Pi, check the blog post "JavaFX on Raspberry PI", which contains some information about the performance of JavaFX, comparing it to native applications.
如果您担心 JavaFX 在 Raspberry Pi 上的性能,请查看博客文章“JavaFX on Raspberry PI”,其中包含有关 JavaFX 性能的一些信息,并将其与本机应用程序进行比较。
Update: Test results after running Tomcat 7 with Java 8 on the Pi
After I got the 512mb version of the Pi (MODELL B), I installed Java 8 and Tomcat 7.0 without any problems. Tomcat examples were working, and I was able to use the Tomcat manager application without any problems.
更新:在 Pi 上运行带有 Java 8 的 Tomcat 7 后的测试结果
在我获得 512mb 版本的 Pi(型号 B)后,我安装了 Java 8 和 Tomcat 7.0,没有任何问题。Tomcat 示例正在运行,我能够毫无问题地使用 Tomcat 管理器应用程序。
With 64 MB of RAM used for the graphics card, I still had 291 MB of free memory (with sshd running):
使用 64 MB RAM 用于显卡,我仍然有 291 MB 可用内存(运行 sshd):
pi@raspberrypi ~/ $ free -m
total used free shared buffers cached
Mem: 438 146 291 0 10 74
-/+ buffers/cache: 60 377
Swap: 99 0 99
pmap
reported a total of 192 MB being used by the Tomcat process.
pmap
据报告,Tomcat 进程总共使用了 192 MB。
回答by Joseph Ottinger
Right now, a JVM on the pi is possiblebut a Java SE edition is hard to find. There may be one for ARM from Oracle, but I haven't tried it (my pi is still on it's way) and if memory serves it's behind a wall.
现在,pi 上的 JVM 是可能的,但很难找到 Java SE 版本。可能有一个来自 Oracle 的 ARM,但我还没有尝试过(我的 pi 还在路上),如果没记错的话,它就在墙后。
Another limitation for the pi is the available RAM; apps like jboss and glassfish are going to want more RAM than the pi provides, except under very constrained deployments.
pi 的另一个限制是可用的 RAM;像 jboss 和 glassfish 这样的应用程序需要比 pi 提供的更多的 RAM,除非在非常受限的部署下。
回答by James R. Perkins
回答by Toilal
Raspberry Pi has only 185MB available for the whole JVM. (after boot, with 16MB to video processing).
Raspberry Pi 只有 185MB 可用于整个 JVM。(启动后,有 16MB 用于视频处理)。
Then, you need to use aggresive and precise memory options (-Xmx120M -XX:MaxPermSize=55M -XX:ReservedCodeCacheSize=4M -Djava.awt.headless=true
)
然后,您需要使用积极而精确的内存选项 ( -Xmx120M -XX:MaxPermSize=55M -XX:ReservedCodeCacheSize=4M -Djava.awt.headless=true
)
I have made an application based on Jetty, Spring 3 and Hibernate/JPA. Just after deployment, it fit in about 15MB of Heap space and 32MB of non heap space (using JProfiler memory analysis)
我制作了一个基于 Jetty、Spring 3 和 Hibernate/JPA 的应用程序。刚刚部署后,它适合大约 15MB 的堆空间和 32MB 的非堆空间(使用 JProfiler 内存分析)
Each loaded class is permanent memory lost, because PermGen space can't be garbage collected. A lot of classes are loaded only for initialization support, but will stay loaded forever. Maybe tweeks can be found to consume less PermGen space for each component.
每个加载的类都会永久丢失内存,因为 PermGen 空间不能被垃圾回收。许多类只是为了初始化支持而加载,但会永远保持加载状态。也许可以发现 tweeks 为每个组件消耗更少的 PermGen 空间。
回答by Dmitriy R
I use TJWS on Raspberry Pi under JRE 1.7, it works incredibly fast and no memory issues.
我在 Raspberry Pi 上使用 JRE 1.7 下的 TJWS,它运行得非常快并且没有内存问题。
回答by Andrew p
Ive got tomcat7 running on openjdk with sqlite databases. Processing ok at around a quater speed of my laptop, but opening jsp pages takes 10-15 seconds. Not sure why yet.
我已经在带有 sqlite 数据库的 openjdk 上运行了 tomcat7。处理速度大约是我的笔记本电脑的四分之一,但打开 jsp 页面需要 10-15 秒。还不知道为什么。
回答by Vsevolod Golovanov
Arun Gupta made a few posts about running JBoss Wildfly on Raspberry Pi.
Arun Gupta 发表了一些关于在 Raspberry Pi 上运行 JBoss Wildfly 的帖子。
回答by Frank
in case you want to use java 11 and javafx I found this is definitely possible with the Liberica JDK of BellSoft: https://bell-sw.com/pages/java-11.0.3
如果您想使用 java 11 和 javafx,我发现这绝对可以使用 BellSoft 的 Liberica JDK:https://bell-sw.com/pages/java-11.0.3
Install scripts and demo application are available on my blog: https://webtechie.be/2019/04/16/pijava-overview-java-11-and-javafx-11-on-raspberry-pi
我的博客上提供了安装脚本和演示应用程序:https: //webtechie.be/2019/04/16/pijava-overview-java-11-and-javafx-11-on-raspberry-pi
To install JDK 11.0.2:
安装 JDK 11.0.2:
# Make sure we are in the home directory
cd /home/pi
# Download the Java 11.0.2 distribution from BellSoft
wget https://download.bell-sw.com/java/11.0.2/bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz
# Move the downloaded file to /opt
sudo mv bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz /opt
# Use the /opt directory
cd /opt
# Untar the downloaded file
sudo tar -xvzf bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz
# Remove the downloaded file
sudo rm bellsoft-jdk11.0.2-linux-arm32-vfp-hflt.tar.gz
Testing and running Java file without compiling:
在不编译的情况下测试和运行 Java 文件:
cd /home/pi
nano HelloWorld.java
public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World");
}
}
/opt/jdk-11/bin/java /home/pi/HelloWorld.java
Hello World