Raspberry Pi - Running Java app on Raspbian

Background

So I installed a fresh copy of Raspbian onto my Raspberry Pi Model B, expanded the file system and all the other stuffs you need to do when you've first set up a Raspberry Pi.

I wanted to use the Raspberry Pi to control my biped robot called Aimie. The method I chose to control my robot was via a serial connection using the io ports on the side of the Raspberry Pi. Trouble is, I developed my Java application on Windows 8.1 and had no idea how to get it working on Raspbian.

Before you start

Before you do anythign with a Raspberry Pi, I recommend you use Bitvise SSH Client, it will allow you to remotely control your Raspberry Pi when you need it. This is very usefull because undoubtbly you will be using the keyboard from your main computer and still have the need to Google things, so a remote connection using SSH really helps.

SSH should be installed and enabled by default, if not use this page.

Use the default login for SSH

Username: pi
Password: raspberry

Update

Run the following commands to update before you continue...

sudo apt-get clean
sudo apt-get update

Check Java version

You can check the Java version on the Raspberry Pi using the following command...

java -version

 Copying files to the Raspberry Pi

By default Bitvise supports sftp which allows you to transfer files to and from your Raspberry Pi whilst you have an open SSH connection. For my project, I used it to transfer my robots AI program. See figure 1.

Figure 1:
SSH SFTP

Note: Bitvise sFTP should open automatically when you first connect to your Pi.

Running your Java application

Browse to the location of your jar using this command...

cd /home/pi/mynewfolder

You should now be able to run your Java app using the following command...

java -jar myfilename.jar

 That's it

Hopefully that helps anyone who get's stuck, if you have any more questions, leave a message in the comments section below.


Published at

Tags: Java,Raspberry Pi

Luke Alderton

Comments

annualmars
i tried that but it says it cant access the jar file
10/05/2019
Paolo
How would I go about running a javar -jar command after i close ssh or remote desktop??? i ask as im running a nukkit minecraft server and right now, in order to run it, i have to have ssh left open on my laptop, how would i run it and close ssh??
19/04/2020
Ben
I am also getting the "Error: Unable to access jar file Filename.jar" I have made sure to set the directory and set my JAVA_HOME, and about everything under the start. I have been pulling my hair out for a while over it.
24/05/2020
Nick
I'm a new starter and found that i was getting the same - after i followed the case of the files it was fine -- who/why would anyone make a title case sensitive
14/10/2020
Mr. Greymatter
Try going to the properties of the Java app/zip file and under the permissions tab check the option to make it executable by anyone.
16/02/2021
Share with
Tags
Latest Comments
By Mark Gentry on Windows Server 2019 - Change product key does nothing
20 Aug 2021, 03:30 AM
By Cathy on In-Place Upgrade for a Windows Server domain controller
31 Jul 2021, 18:28 PM
By Mr. Greymatter on Raspberry Pi - Running Java app on Raspbian
16 Feb 2021, 07:35 AM
By Mikko Seittenranta on Xamarin Forms multiple instances of same app open
16 Feb 2021, 04:34 AM
By Andrew on Auto/Custom height on Xamarin Forms WebView for Android and iOS
22 Jan 2021, 22:15 PM
By Nick on Raspberry Pi - Running Java app on Raspbian
14 Oct 2020, 19:37 PM
By Ivan on Fixed: Value cannot be null Parameter Name: source
15 Sep 2020, 19:47 PM
By Anand on Raspberry Pi - Bluetooth using Bluecove on Raspbian
7 Sep 2020, 16:53 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development