I'm interested is it possible to compile Java code to native code so that I can run it on some cheap board like Arduino or Raspberry pi?
What compiler can you recommend?
-
1Yes you can run java on the Raspberry Pi. It is like any other Linux computer that way. I don't know of any Java support for the arduino.Steve Robillard– Steve Robillard2016年01月04日 16:03:17 +00:00Commented Jan 4, 2016 at 16:03
-
1There are two JDKs available I'm aware of, Oracle 8 for ARM, and the open source Iced Tea that's in the Raspbian repos.goldilocks– goldilocks2016年01月04日 16:32:35 +00:00Commented Jan 4, 2016 at 16:32
-
@SteveRobillard - There is JArduino which might fit the bill.Greenonline– Greenonline ♦2016年01月05日 16:16:55 +00:00Commented Jan 5, 2016 at 16:16
-
1@Greenonline thanks, note I did say I didn't know of any but I do now.Steve Robillard– Steve Robillard2016年01月05日 16:20:40 +00:00Commented Jan 5, 2016 at 16:20
2 Answers 2
Yes, you can compile java code to native for example using gcj
and run it on Raspberry Pi. But you can also run a complete java stack on the pi, no problem.
On the Arduino, you could take a look at JArduino library, take a look at this answer to Control an Arduino with Java. It provides a Blink example written in Java.
You will need to update the Arduino firmware first though:
Before using JArduino, please make sure your Arduino board contains the JArduino firmware:
- Copy the JArduino folder (located in the distribution in
org.sintef.jarduino.samples/arduino
) into/libraries/
- Launch your Arduino environment
- File -> Examples -> JArduino -> JArduino firmware. It should open an Arduino program that you should upload to your board using the normal Arduino procedure.
- Your Arduino board is now ready for Jarduino. You can exit the Arduino environment forever and launch Eclipse. Just run the Java/JArduino program.