Richiie10
Posts: 1
Joined: Tue Oct 08, 2013 2:50 am

Java NetBeans or Eclipse on Raspberry Pi

Fri Oct 11, 2013 2:04 am

I only have one question about the Raspberry Pi, can I install and start programming with Eclipse or Netbeans in the Raspberry Pi? cause I tried to install booth of them and it's run to slow, I think is the version of the Netbeans and Eclipse, or what could be the problem?

Someone can post a tutorial to run a Java project in the Raspberry Pi? please

ramp
Posts: 8
Joined: Mon Feb 11, 2013 1:19 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Tue Oct 15, 2013 11:10 am

NOTE: Sorry for my english.

Hello Richi,
Eclipse and netbeans are heavy for raspi, in my case, i create an ant build for coding/compile java in mi laptop and after send/run the generated jar file to raspi.

For example (Ant-Build) build.xml:

<?xml version="1.0" ?>
<project name="Ant Raspberry" default="execute">

<property file="build.properties"/>

<patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties" />
</patternset>

<target name="init">
<echo>Creating dirs...</echo>
<delete dir="${classes.dir}" />
<delete dir="${jar.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${jar.dir}" />
</target>

<target name="compile" depends="init">
<echo>Compiling...</echo>
<javac srcdir="${src.dir}" destdir="${classes.dir}" />
</target>

<target name="copy.meta.files" depends="compile">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<patternset refid="meta.files" />
</fileset>
</copy>
</target>

<target name="jar" depends="copy.meta.files">
<echo>Creating Jar...</echo>
<jar jarfile="${jar.dir}/${jar.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${class}"/>
</manifest>
</jar>
</target>

<target name="package" depends="jar">
<jar destfile="${jar.dir}/${jar.name}-release.jar" basedir="${classes.dir}" includes="**/*.*">
<manifest>
<attribute name="Main-Class" value="${class}" />
</manifest>
<zipgroupfileset dir="${lib.dir}" includes="*.jar" />
<zipgroupfileset dir="${jar.dir}" includes="${jar.name}.jar" />
</jar>
</target>

<target name="deploy">
<echo>Sending to Raspi</echo>
<scp remoteTodir="${ssh}:${dest.dir}"
password="${password}"
trust="yes"
sftp="true">
<fileset dir="${jar.dir}">
<include name="${jar.name}-release.jar"/>
</fileset>
</scp>
</target>

</project>

build.properties:

class=xxx.xxx.xxx.Clazz
classes.dir=build/classes
jar.name=theJarName
jar.dir=jar
src.dir=src
ssh=root@192.168.0.10
dest.dir=/root/projects/myProject/
raspi.ip=192.168.0.10
user=root
password=raspberry
lib.dir=lib

Your project must have the next structure:

+ PROJECT_NAME
+-------src (Here your code)
+-------lib (Here the jar libs, for example pi4j)
+-------build.properties
+-------build.xml

And finally you must have download jsch (ssh lib for ant) and add to ant classpath, and select/run targets package and deploy.

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Tue Oct 15, 2013 1:57 pm

I am using eclipse on my windows 7 laptop to develop code for my pi.

In the same way as any project, I have a main class, and when I am happy with it on the PC, in eclipse I do File->export->runnable JAR file and select my main class. This produces a JAR file (optionally with all the required libraries already packaged into it)

I then use a windows explorer window to copy the jar onto a samba share on my pi, and use ssh to debug and run it.
simonmcc.blogspot.com/search/label/pi

User avatar
Douglas6
Posts: 4812
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Java NetBeans or Eclipse on Raspberry Pi

Tue Oct 15, 2013 5:47 pm

An alternative that I use is to run Eclipse on the PC, and access my project code on the Pi's SD card via a Samba share. Advantage, no need to build a jar and copy it on each cycle (Eclipse happily builds the project in-place, on the Pi). Disadvantage, Eclipse gets very confused if the project is open and the pi reboots or otherwise looses connection. It's also a little slower accessing the project at SD card speed.

And I have yet to configure remote debugging, but I'm getting really fast at typing "System.out.println" :) .

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Wed Oct 16, 2013 2:20 pm

It is similar here: I use Eclipse on my (linux) laptop and then sshfs from RPi back to the laptop. That way all class files produced by Eclipse (and/or maven) are instantaneously available on RPi. Only thing I do on RPi is to do java -cp ... to start the code. Sshfs is available for Raspbian (sudo apt-get install sshfs). It is going to work well on OSX, too.

Now I am looking for ways of starting Java process on RPi directly from Eclipse on PC. Worse case scenario, when I get some time I'll write an plugin (if there isn't already one). That way I would be able to do all the development in nice, fast environment with Eclipse and even run and debug code directly on RPi from there...

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Wed Oct 16, 2013 2:25 pm

I suppose it depends on what you're doing, my project has a lot of logic, TCP communications and some GPIO. I develop and test all my code on my windows machine, as it all runs there with a dummy GPIO library, which is changed in a configuration file using spring.

This means I can develop and test without having access to a pi at all, as all the hardware is doing is controlling relays, and for the purposes of testing it's just as good to have a dummy implementation printing that GPIO 1 is going high.

All my C# and java code is developed, tested and refined on windows before I transfer it to the pi, and I would certainly recommend this approach
simonmcc.blogspot.com/search/label/pi

User avatar
Douglas6
Posts: 4812
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Java NetBeans or Eclipse on Raspberry Pi

Wed Oct 16, 2013 8:02 pm

I gotta agree with Simon; the "right" way would be to have some mock classes and maybe an IOC framework like Spring, and do as much building and testing off of the Pi as possible. I mean, this IS Java, after all. My current project makes heavy use of an LCD and input buttons, and I just haven't gotten around to mocking those up. A library of mock Pi4J classes would be handy, maybe someday.

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Thu Oct 17, 2013 7:53 am

My mock actually works a layer above PI4J, I have an IOInterface which looks like this:

Code: Select all

public interface IOInterface {
	public static interface InputReceivedListener {
		void ioInputReceived(int inputNumber, int onOff);
	}

	void addListener(InputReceivedListener listener);

	void setOutput(int outputNumber, int onOff);

}
This is the layer I mock, and the reason for that is that my code used to run on windows and control hardware across a serial port, so I have 3 implementations, GPIO, RS232 and mock.

It's well worth taking time to make these simple design decisions, they help and save time in the long run.
simonmcc.blogspot.com/search/label/pi

sr29067
Posts: 7
Joined: Thu Jan 26, 2012 4:42 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Fri Oct 25, 2013 3:51 pm

For the NetBeans users I just posted a blog entry that explains how to configure a Ras Pi and NetBeans project to do auto-copying of jar files whenever you build a project. Doesn't solve the issue of testing code on a laptop, etc, but does make the whole edit-compile-deploy cycle easier.

https://blogs.oracle.com/speakjava/entr ... spberry_pi

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Sat Nov 23, 2013 3:56 pm

clicky wrote:Now I am looking for ways of starting Java process on RPi directly from Eclipse on PC. Worse case scenario, when I get some time I'll write an plugin (if there isn't already one). That way I would be able to do all the development in nice, fast environment with Eclipse and even run and debug code directly on RPi from there...
Got it! First version has just had successful go!

I have created a simple project (source is here: http://svn.abstracthorizon.org/playgrou ... -launcher/) which has an agent (a daemon that sits on RPi) and client (launcher) you can be used from your IDE. Idea is that the agent will launch new VM (on RPi) and act as a proxy between client and new VM. Then client will send list of all class path resources (provided it was started by URLClassLoader), along with sizes and modification dates. New VM will check local cache (.remotevm dir) and 'download' all changed resources from client machine (your PC). It all speeds modify, run, see results, repeat process of developing Java code for RPi.

First version of the agent (RPi side) jar is here: http://repository.abstracthorizon.org/m ... 3640-1.jar
Start it with

Code: Select all

java -jar remotevmlanucher-agent.jar
(provided that yo have downloaded it to remotevmlanucher-agent.jar file on the RPi)

Client (IDE side) is here: http://repository.abstracthorizon.org/m ... 3652-1.jar
To start your code from for instance Eclipse (or other IDEs/command line) you need to invoke that jar's 'org.ah.java.remotevmlauncher.client.LaunchRemote' class. For instance from Eclipse create launcher for your main class like this:

Main tab of launcher - Main class: org.ah.java.remotevmlauncher.client.LaunchRemote
Arguments:

Code: Select all

pi2:8999
org.ah.pi.test.Clock
--
/sys/bus/w1/devices/28-000004d41cd5/w1_slave
And in Classpath tab 'Add External Jars...' - pointing to client jar above.
In above example pi2 is my RPi local address (can be IP address), 8999 is default port of the agent (you can start agent with --help to see parameters) and org.ah.pi.test.Clock is main class I would like to run on RPi. Everything that is after '--' go as arguments on RPi side.

Classpath on PC side should look exactly as you would like it to look - all the directories, jar, maven repository jars - all will be transferred to RPi on first go and updated when they update on client.

I'll create detailed tutorial for pure Eclipse and maven projects in following days. Currently I am not sure if client jar will work on Windows platform (I have plans to test and fix issues if there are any). Enjoy

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Sat Nov 23, 2013 10:28 pm

Here's first few sentences of how to remotely launch Java application from development machine's IDE on RPi:

http://remotevm.abstracthorizon.org/

I'll do some more in following days.

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Sat Nov 30, 2013 9:57 pm

I've just updated it so it works from Windows client machines. Tutorials are to follow... Until then use downloads from this page:
http://remotevm.abstracthorizon.org/usage.html

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Sat Dec 14, 2013 6:13 pm

Sorry for slightly hi-jacking the thread - I'll create new in a following days. Until then, just quickly to say that I've added the tutorial for pi4j on RPi with Eclipse on local PC:
http://remotevm.abstracthorizon.org/ecl ... orial.html

First part is somewhat for total beginners while last two chapters are for advanced use. Including remotely starting and debugging Java application.

PIsingh
Posts: 12
Joined: Tue Dec 24, 2013 11:52 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Sun Dec 29, 2013 10:17 am

clicky wrote: just quickly to say that I've added the tutorial for pi4j on RPi with Eclipse on local PC:
http://remotevm.abstracthorizon.org/ecl ... orial.html
this is the best think ever man!!!! i have been looking for something like this for a while now. Thank you so so so so much.

User avatar
clicky
Posts: 425
Joined: Thu Oct 25, 2012 7:34 am

Re: Java NetBeans or Eclipse on Raspberry Pi

Sun Dec 29, 2013 10:27 am

I've just found a bug when you want to send too much text output (System.out) while I have been testing WiiMotePlus gyro on RPi... Also found a few typos on usage page. I'll be fixing those today/tomorrow and upload next version. Plus I am dying to add another feature: jar to stop on inactivity - so when you leave it for (let's say 30 minutes) without any active session nor started new session, it will just stop on its own.

PIsingh
Posts: 12
Joined: Tue Dec 24, 2013 11:52 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Wed Jan 01, 2014 1:17 am

clicky wrote: http://remotevm.abstracthorizon.org/ecl ... orial.html

First part is somewhat for total beginners while last two chapters are for advanced use. Including remotely starting and debugging Java application.
I am a beginner and there are quite a lot that i don't understand but i am going with it. I have been able to compile simple java programs as jar then copy the jar to pi. It works fine. But now i want to do the same but with pi4j, i usually put the code in text file then use the class path for pi4j to compile and execute on pi.
But i want to compile it on my computer then move it to pi. I have followed the tutorial, the vm agent.jar is running on the pi etc. but i get an error in eclipse
<--Pi4J--> GPIO Control Example ... started.
java.io.IOException: Cannot run program "bash": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:45)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:40)
at com.pi4j.system.SystemInfo.getBashVersionInfo(SystemInfo.java:441)
at com.pi4j.system.SystemInfo.access$000(SystemInfo.java:43)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:193)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:190)
at java.security.AccessController.doPrivileged(Native Method)
at com.pi4j.system.SystemInfo.isHardFloatAbi(SystemInfo.java:190)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:153)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:138)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:47)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:102)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:67)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:85)
at org.ah.remotevm.tutorial.GpioExample.main(GpioExample.java:13)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 18 more
java.io.IOException: Cannot run program "/usr/bin/readelf": CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:45)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:40)
at com.pi4j.system.SystemInfo.getReadElfTag(SystemInfo.java:472)
at com.pi4j.system.SystemInfo.hasReadElfTag(SystemInfo.java:459)
at com.pi4j.system.SystemInfo.access$100(SystemInfo.java:43)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:193)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:190)
at java.security.AccessController.doPrivileged(Native Method)
at com.pi4j.system.SystemInfo.isHardFloatAbi(SystemInfo.java:190)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:153)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:138)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:47)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:102)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:67)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:85)
at org.ah.remotevm.tutorial.GpioExample.main(GpioExample.java:13)
Caused by: java.io.IOException: CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 19 more
java.io.IOException: Cannot run program "bash": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:45)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:40)
at com.pi4j.system.SystemInfo.getBashVersionInfo(SystemInfo.java:441)
at com.pi4j.system.SystemInfo.access$000(SystemInfo.java:43)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:193)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:190)
at java.security.AccessController.doPrivileged(Native Method)
at com.pi4j.system.SystemInfo.isHardFloatAbi(SystemInfo.java:190)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:154)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:138)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:47)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:102)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:67)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:85)
at org.ah.remotevm.tutorial.GpioExample.main(GpioExample.java:13)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 18 more
java.io.IOException: Cannot run program "/usr/bin/readelf": CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:45)
at com.pi4j.util.ExecUtil.execute(ExecUtil.java:40)
at com.pi4j.system.SystemInfo.getReadElfTag(SystemInfo.java:472)
at com.pi4j.system.SystemInfo.hasReadElfTag(SystemInfo.java:459)
at com.pi4j.system.SystemInfo.access$100(SystemInfo.java:43)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:193)
at com.pi4j.system.SystemInfo$2.run(SystemInfo.java:190)
at java.security.AccessController.doPrivileged(Native Method)
at com.pi4j.system.SystemInfo.isHardFloatAbi(SystemInfo.java:190)
at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:154)
at com.pi4j.wiringpi.Gpio.<clinit>(Gpio.java:138)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:47)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:102)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:67)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:85)
at org.ah.remotevm.tutorial.GpioExample.main(GpioExample.java:13)
Caused by: java.io.IOException: CreateProcess error=3, The system cannot find the path specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 19 more
Dec 31, 2013 5:08:49 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: Failed to load library [pi4j] using the System.load(file) method using embedded resource file: [jar:file:/C:/Documents%20and%20Settings/Administrator/Workspaces/Eclipse%20Standard%20431/eclipse-remote-vm-pi4j-rpi-tutorial/lib/pi4j-core.jar!/lib/soft-float/libpi4j.so]
Dec 31, 2013 5:08:49 PM com.pi4j.util.NativeLibraryLoader load
SEVERE: ERROR: The native library [pi4j : libpi4j.so] could not be found in the JVM library path nor could it be loaded from the embedded JAR resource file; you may need to explicitly define the library path '-Djava.library.path' where this native library can be found.
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.pi4j.wiringpi.Gpio.wiringPiSetup()I
at com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)
at com.pi4j.io.gpio.RaspiGpioProvider.<init>(RaspiGpioProvider.java:47)
at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:102)
at com.pi4j.io.gpio.impl.GpioControllerImpl.<init>(GpioControllerImpl.java:67)
at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:85)
at org.ah.remotevm.tutorial.GpioExample.main(GpioExample.java:13)

PIsingh
Posts: 12
Joined: Tue Dec 24, 2013 11:52 pm

Re: Java NetBeans or Eclipse on Raspberry Pi

Wed Jan 01, 2014 1:49 am

I had some time on my hands, so i decided to do the whole tutorial again.. [http://remotevm.abstracthorizon.org/ecl ... orial.html]
this time even though i didn't get the long error as before, but i got a small error saying........
please help

Exception in thread "main" java.lang.NullPointerException
at java.net.Socket.<init>(Socket.java:418)
at java.net.Socket.<init>(Socket.java:241)
at org.ah.java.remotevmlauncher.client.LaunchRemote.setup(LaunchRemote.java:112)
at org.ah.java.remotevmlauncher.client.LaunchRemote.main(LaunchRemote.java:402)

Return to “Java”