How to setup Eclipse on Windows PC for development of RPi application using Pi4J

3,376 views
Skip to first unread message

Kenson Leung

unread,
Oct 6, 2013, 10:40:47 AM10/6/13
to pi...@googlegroups.com
Hi all. I am a traditional java guy and purchased a RPi once I see this great Pi4J project.
I have completed the pi4j installation on my Pi.
I know the Pi is now powerful enough to run eclipse. However, it would be more convenient to develop the application on PC and debug/run on Pi.

I guess most of you here have been doing this. May I know how to setup the development environment?

Thanks!
Kenson Leung
Hong Kong

Robert Savage

unread,
Oct 6, 2013, 1:23:26 PM10/6/13
to pi...@googlegroups.com
Hi Kenson,

I do all my development on my workstation or laptop, I don't run eclipse on the Pi.
The only real setup required for eclipse (or other IDE) is to import the pi4j libraries into your project.  
You can download the ZIP package of the Pi4J libraries, unzip them into your project and reference the JARs from eclipse.  

Or .. if you familiar with Maven, you can simply include the Pi4J library JARs in your <dependencies> section.  

The one thing you cannot do (at least not at this time) if run your program from eclipse on the PC/laptop.  
You must execute your program directly on the RPi.   

Personally, I am using some additional steps in my Maven build to transfer the compiled version of my program using SSH over to the RPi hardware.  I then run and test my program on the RPi.  

I am planning on writing an article (soon) on how I use Maven to fully instrument my build and deployment environment on my blog at www.savagehomeautomation.com.  You can follow me on Twitter as @savageautomate to be notified when new articles are posted. 

Thank You,
Robert

Rafael Bandeira Rodrigues

unread,
May 9, 2017, 5:06:03 PM5/9/17
to Pi4J
I'm Having the same problem here.

I can code on netbeans and depploy and test direct on raspberry pi from something called "Remote Standard Java Edition" on Netbeans. But i can't find nothing that works like it on eclipse.

Tom Moyer

unread,
Jan 28, 2018, 8:42:23 PM1/28/18
to Pi4J
A couple tweaks which make this easier for me:
   The core of the functionality is to use IDE of your choice on the fastest, most familiar platform with your favorite editor.   For me this is a gaming Windows system with Eclipse, sublime text, MobaXTerm, and VNC Viewer.   The tradeoff is quicker response in the writing debugging, vs the need to a jar over to the Pi before being able to run.  
     Using MobaXterm gives you a GUI drag/drop-able file transfer capability (WinScp does too, but I prefer Mobas choice of providing a CLI terminal instead of second a window's explorer view of my host windows system).    If you're running headless, you have your terminal right there.   If you need the Pi's GUI output, window swapping to the VNC gets you everything except PI camera preview's.
    The second trick is to compile to a runnable jar, using the eclipse option to   "copy the required libraries into a sub-folder next ot the generated JAR"
This is advantageous because it allows you to copy the vast bulk of the required bytes only once (the MyRunnableJarName_lib directory holds all the full load of a maven project with 100MB).   As you make incremental changes to the program it is only the < 1MB MyRunnableJarName.jar file which changes.    Drag/drop transfer of the jar takes only a second or two. 
  Setting up a couple of mini-caller scripts allows two things.   You can call either the runnable jar default main class, or any other class compiled into that same jar (when your java projects have several 
entry classes) with only 6 keystrokes.    s   h   space   zero   tab  enter         or            s   h   space one   tab   enter  will call the two scripts below
   0_run_blink.sh 
#!/bin/bash
# This calls whatever class was compiled for the runnable jar
# Dynamic linking required because the Noobs has a downlevel, pre Rpi3B wiringPi
sudo java -Dpi4j.linking=dynamic -jar Pi4J_Demos.jar

   1_run_blink.sh
#!/bin/bash
# calls a specific class, even if the jar is runnable for another class
# Dynamic linking required because the Noobs has a downlevel, pre Rpi3B wiringPi
sudo java -Dpi4j.linking=dynamic -cp Pi4J_Demos.jar myJavaStuff.I2CExample
Reply all
Reply to author
Forward
0 new messages