Mennims
Posts: 105
Joined: Sun May 19, 2013 9:37 am

Remote Java programming

Tue Feb 17, 2015 8:48 am

I'd like to do my Java programming on my PC and export it to my Pi, then execute it. All automatically through Eclipse. I want to do a massive GPIO project with Pi4J, and I tried using Java ME, and it does what I want it to. I can write my program, then execute it on the Pi, then the output is forwarded back to my PC. I am using the Pi 2 B, and I don't want to use ME, I would prefer SE, so is there any way I can do that with SE? I don't want to have to manually move the file across then run it just to test

User avatar
Fidelius
Posts: 460
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Remote Java programming

Tue Feb 17, 2015 9:58 am

I only know that with Netbeans IDE it is very simple to achieve, what you're asking for. I described it here: Integrating NetBeans for Raspberry Pi Java Development.

Maybe there's a similar helper/plugin for Eclipse?

On the Pi2, Netbeans runs fast enough to directly develop, run and debug there. Now one could remote run Java apps on the Linux PC. :-)
Last edited by Fidelius on Tue Feb 17, 2015 6:30 pm, edited 1 time in total.


bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

Re: Remote Java programming

Tue Feb 17, 2015 11:16 pm

This is what you are looking for: http://www.raspberrypi.org/forums/viewt ... 68#p694568

It's a tiny HTTP server with hot-deploy, I'm using it for everything, but of particular interest to you a COM port radio.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Remote Java programming

Tue Feb 17, 2015 11:32 pm

"massive project" "the file", these 2 shouldnt really occur in the same paragraph. Massive projects ought to be splint in to many modules and separate class files. Testing should be of individual small components so workflow would be modify a class, send class to RPi, run test.
Even better might be to use reflection, thereby only the GPIO (JNI or whatever) classes need to be on the RPi during development.
Or.. would a RPi emulator running on the PC do the job?
>)))'><'(((<

Mennims
Posts: 105
Joined: Sun May 19, 2013 9:37 am

Re: Remote Java programming

Wed Feb 18, 2015 5:09 am

aTao wrote:"massive project" "the file", these 2 shouldnt really occur in the same paragraph. Massive projects ought to be splint in to many modules and separate class files. Testing should be of individual small components so workflow would be modify a class, send class to RPi, run test.
Even better might be to use reflection, thereby only the GPIO (JNI or whatever) classes need to be on the RPi during development.
Or.. would a RPi emulator running on the PC do the job?
Doesn't mean the actualy Java programming is the massive part of this project. I just said massive project. It is a massive project for us.

Mennims
Posts: 105
Joined: Sun May 19, 2013 9:37 am

Re: Remote Java programming

Wed Feb 18, 2015 5:31 am

Clicky, thank you so much. I went through so much trouble with the previous reply, because I don't prefer Netbeans, and had to download a special EJDK and a whole lot of stuff. I'm sure it'll be good for Netbeans users, just not me. But thank you Clicky for LaunchPi, I don't have issues with my libraries as well anymore!

bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

Re: Remote Java programming

Wed Mar 04, 2015 7:32 pm

But with this you restart your java process, which takes time. My solution is instantaneous = ~1 sec total round trip. Turnaround is important!
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

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

Re: Remote Java programming

Thu Mar 05, 2015 9:44 am

Fair enough. But there's a difference between fully pledged, stand alone java app vs specific app container.
If you are making your own java app then there's different approach to developing for your app container.

Also - there's a question how do you prepare your classes for hot deployment and deliver them to the RPi so Rupy can pick them up?

And last thing is inevitable resource leak in hot deployment - perm space is especially prone being affected. So you'll need to restart your app container from time to time...

bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

Re: Remote Java programming

Thu Mar 05, 2015 10:06 am

clicky wrote:Fair enough. But there's a difference between fully pledged, stand alone java app vs specific app container.
If you are making your own java app then there's different approach to developing for your app container.
Yes, but once you get it working you won't be able to believe you ever worked in any other way. And you can use hot-deploy for all your projects! And you can use any IDE.
clicky wrote:Also - there's a question how do you prepare your classes for hot deployment and deliver them to the RPi so Rupy can pick them up?
You just jar them up and deploy them like demonstrated in the page tutorial. After you modify your pass in the build.xml from secret, on the server with -pass and change localhost to the raspberry pi IP.

Or with this command: java -classpath lib/http.jar se.rupy.http.Deploy IP:PORT YOUR.JAR PASSWORD
clicky wrote:And last thing is inevitable resource leak in hot deployment - perm space is especially prone being affected. So you'll need to restart your app container from time to time...
The good thing about rupy is that you only deploy your code and the libs are in the bootclasspath, so you might have to restart rupy once per year on the dev machine.

Let me know if you have any trouble, I'm here to help!
Last edited by bullen on Thu Mar 05, 2015 10:19 am, edited 2 times in total.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

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

Re: Remote Java programming

Thu Mar 05, 2015 10:17 am

See, that's the main issue: you need to jar your stuff before hot-deploying them. Unlike that, remotevm project (and probably LaunchPi) does different thing: you run your development from your IDE from a laptop/PC and remotevm client in collaboration with remotevm agent transfer only changed files across the wire and restart new VM.

In everyday work it is quite fast: you change a bit of code in one of the classes, press 'run' button in your IDE (Eclipse for instance) and couple of seconds later you see result in Console of the IDE + effect in RPi. Quite fast and trouble free development. And it replicates development of Java on the same box: no extra steps between changing code and running it.

What you're advocating is several steps between changing code and running. Mere process of creating jar usually takes at least one more 'click' and several seconds + transferring jar to RPi, etc...

Having said all of it - Ruby is really nice lightweight HTTP server, and as such has its place. Only issue is that I just cannot see it as a part of regular java app remote java programming for RPi.

bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

Re: Remote Java programming

Thu Mar 05, 2015 10:25 am

Well, you won't know for sure until you have tried.

I can deploy anywhere, port 80 is always open, to a cluster of raspberry pi's for example in my radio development, which is something you won't be able to do.

Basically I found one way I can work remotely on every project involving HTTP, and it's amazing.

Building the jar makes sure your deployment is the same everywhere, eliminating those "but it work(s/ed) on dev" frustrations completely and forever, and it takes maybe 10 ms on my computer.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

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

Re: Remote Java programming

Thu Mar 05, 2015 10:39 am

Again - feature of your HTTP server is pretty cool.

But I think you're mixing *development* and *deployment*.

In first case you need really quick turnaround between change and seeing result - they way we used on in our IDE: change the class, press run, see the result, react on it and repeat.

Deployment is where you want reproducibility - where build tools like Maven get in the picture and you build your solution and deploy it to target machine. You've made that part really easy (deployment) - hats off. But that's not *development* tool or process I would like to follow. Quick hack to existing running system - fine. Hours of coding and seeing results - no, thanks.

And, as I said earlier - with all other solutions mentioned here in this forum you are not 'depending' on solutions (the same way you *shouldn't* depend on your faviourite IDE) you're merely using them as tools. With your proposed solution, one would need to adopt Rupy as target app container (is it really a fully fledged app container or just mere HTTP server/container?) and code *for* it. That won't get the traction you're maybe hoping.

For example: why would I want to use Rupy for my tool chain for my 3D printer? I want to code in Java for RPi for my 3D printer. I want to make command line tools for it. And I can easily develop it with any of mentioned options here - but I don't want to to rely on Rupy as it has nothing to do with web server. Also, my other project that *involve* HTTP server - I'm quite happy with one already provided by JDK and I don't need extra dependency.

Again - this is nothing against your HTTP server - as I said - I really like it and having it as a potential HTTP server to switch to in the future for some of the projects. I am just saying that I don't think it has anything to do with *general* Java *development* on RPi. Had this topic been 'help me to choose HTTP server for easy deployment on RPi - they Rupy would be real contender in that context. Including your hot deployment.

jingram
Posts: 2
Joined: Sun Oct 09, 2016 5:54 am

Re: Remote Java programming

Sun Oct 09, 2016 6:03 am

Hi

If you have a Maven based project you can switch out the Maven Exec plugin with a SSH Exec plugin.
https://bitbucket.org/jingram/ssh-maven-plugin/overview

The plugin will automatically connect via SSH to the pi given the host, port and username / password credentials.
It will then automatically upload the Maven project dependences (all those JARs your project requires) and then execute the Java project as a remote Java process on the Pi.

You can also attach a debugger to the remote process for debugging in your IDE.

To enable this in Netbeans, add the following plugin to your pom.xml replacing the configuration with your own.

<build>
<plugins>
<plugin>
<groupId>org.rogueware.mojo</groupId>
<artifactId>ssh-exec-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<sshHost>10.0.0.1</sshHost>
<sshUsername>pi</sshUsername>
<sshPassword>raspberry</sshPassword>
</configuration>
</plugin>
</plugins>
</build>

In Netbeans, replace the Maven actions to use the ssh exec instead of the standard org.codehaus.mojo exec as follows:

Right click on the Maven project in the Projects tab
Select Properties
Click on Actions
Select "Run project" in the actions list
Replace "org.codehaus.mojo:exec-maven-plugin:1.2.1:exec" with "org.rogueware.mojo:ssh-exec-maven-plugin:1.0:exec" in the Execute Goals
Select "Debug project" in the actions list
Replace "org.codehaus.mojo:exec-maven-plugin:1.2.1:exec" with "org.rogueware.mojo:ssh-exec-maven-plugin:1.0:exec" in the Execute Goals

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

Re: Remote Java programming

Sun Oct 09, 2016 7:53 pm

@jingram - thanks for posting it! I was just getting ready to fix my home automation project with some proper deployment scripts and you saved me trouble getting it myself. Your solution is perfect for 'releases'! Cheers! :)

Yaytay
Posts: 8
Joined: Tue Feb 23, 2016 7:49 am

Re: Remote Java programming

Mon Oct 10, 2016 1:01 pm

There is another approach, which will work for some circumstances.

If you run pigpiod on the pi you can then run the Java code anywhere you like, talking to pigpiod via its network API.

I write my code on my PC, play with it there until it's working, and only then do I run it on the pi.

I have a 100% java library for talking to the pigpiod network API - I always planned to Open Source it when it was complete, but getting it complete is a bit awkward because writing unit tests for some of the more esoteric things in pigpiod is non-trivial.

Anyway, let me know if you want me to stick what I've got on BitBucket.

Jim

Return to “Java”