Page 1 of 1

Introducing JBerries

Posted: Thu Jan 09, 2014 6:58 pm
by zeddex
Hi

To help with developing Java code on the Pi I've put together a simple IDE named JBerries.

It provides a multi-window text-editing environment complete with syntax-colouring, find/replace, code-folding, bookmarks, keystroke macros and code templates. Java programs can be compiled and run as single files or as multi-file projects. Integrated error/warning handling allows problem code to be located easily by clicking the messages in the IDE's output window. Programs can be run via a terminal window or from within the IDE with output appearing in (you guessed it) the output window.

JBerries invokes the Java compiler directly using the Java tools API meaning that once the compiler has been loaded the first time, subsequent compiles should be faster providing a noticable productivity gain on using the compiler from the command line.

JBerries is written in Java Swing and has been designed to be as lightweight as possible with a memory footprint low enough to be used on a Model A. It is free software (GPL 3) and can be downloaded from SourceForge at http://sourceforge.net/projects/jberries/

There you will find a .deb file; install using dpkg:

Code: Select all

sudo dpkg -i jberries-1.0.37.deb
There are no dependencies other than a Java JDK. To make life easier (for me!) the .deb doesn't specify any dependencies so you will need to ensure Java is available yourself. With the latest Raspbian image you should have everything you need. Once installed you should find a menu entry under "Programming".

It's not NetBeans but at least it'll run on the Pi!

Steve

Re: Introducing JBerries

Posted: Fri Jan 10, 2014 5:19 pm
by suipaste
sounds interesting, going to give it a try now!

Edit:

Just had a little play around and I'm very happy as I managed to compile a program using jBerries which I previously couldn't workout how to do via terminal! :D

Question:

If I wanted to compile and run taking advantage of the pi4j library how would I do that?
I assume I can use the options in the build preferences to tell the program where the library are located, however I don't completely understand how this works.

I just know that if I was to compile the program via terminal I would do it like so-

Code: Select all

cd /opt/pi4j/examples
javac -classpath .:classes:/opt/pi4j/lib/'*' -d . PiFaceExample.java

To run the sample, use the following command:

cd /opt/pi4j/examples
sudo java -classpath .:classes:/opt/pi4j/lib/'*' PiFaceExample
Presumably that file path should be entered into the build preferences but I'm not sure exactly how it should look.

Re: Introducing JBerries

Posted: Fri Jan 10, 2014 7:52 pm
by zeddex
Hi

Yes, you'll need to add the relevant pi4j jar files to the Java classpath. To do this access Preferences from the Tools menu and select the Build tab. Click the Edit button next to 'Java class path' and enter the full paths of the jar files you need, one per line, and click save.

Image

The classpath settings apply to both compile- and runtime so you only need to set them up once. The Build tab provides the configuration for all single-file programs so any files you create outside of a project will get the same classpath.

For a project, the process is similar except you define the classpath in the project properties dialog, accessed by right-clicking the project root icon in the project window.

Hope that helps,

Steve

Re: Introducing JBerries

Posted: Fri Jan 10, 2014 8:04 pm
by zeddex
If you're working with the GPIO pins you might want to run your program in a terminal. By default program output appears in the IDE output window and is non-interactive; all the program output is gathered together and presented in the window once the program has completed. To allow interactive/real-time output select 'Run in terminal' from the build configuration tab.

The terminal will close automatically once the program has completed so you might want to add something like this

Code: Select all

if (System.console() != null)
	System.console().readLine("\nPress ENTER to continue");
to keep it open.

(Quick tip: in the editor type petc and press ctrl+shift+space to use the code template for this code.)

Re: Introducing JBerries

Posted: Fri Jan 10, 2014 9:49 pm
by suipaste
Yes very helpful!

The only thing I'm stuck with now is this message:

Code: Select all

wiringPi
Must be root to call wiringPiSetup().
Did you forget sudo?
How do you tell the compiler to compile as sudo?

Re: Introducing JBerries

Posted: Fri Jan 10, 2014 10:31 pm
by zeddex
The compiler runs as part of the IDE so if you want to compile as root you'll have to run JBerries as root. One way to do this is to copy the JBerries startup script (/usr/bin/jberries) and update it to this:

Code: Select all

#!/bin/sh
sudo java -splash:/usr/lib/jberries/jberries-loading.png -jar /usr/lib/jberries/JBerries.jar "[email protected]"
This should run JBerries as root.

As you're now running as a different user you'll have to recreate the JBerries config. You can set the project home to point to your original project directory so you won't have to transfer your source files.

Good luck! ;)

Re: Introducing JBerries

Posted: Sat Jan 11, 2014 12:42 am
by suipaste
So close haha. I changed the start up script but I can't get it to run from terminal now. (I'm using SSH with Xming).
Is this because of the config stuff and if so how do you change that?

Here's what I get at the moment:

Code: Select all

[email protected] ~ $ sudo jberries &
[1] 2454
[email protected] ~ $ PuTTY X11 proxy: wrong authorisation protocol attemptedPuTTY X11 proxy: wrong authorisation protocol attemptedException in thread "main" java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:119)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at java.awt.Toolkit$2.run(Toolkit.java:868)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:860)
        at java.awt.Toolkit.getEventQueue(Toolkit.java:1730)
        at java.awt.EventQueue.invokeLater(EventQueue.java:1217)
        at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1290)
        at net.sf.jberries.MainClass.main(MainClass.java:26)

Re: Introducing JBerries

Posted: Sat Jan 11, 2014 10:03 am
by zeddex
I can't provide any help with Xming as I've never used it. Have you tried running directly on the Pi?
Alternatively, I'm guessing you don't actually need root to compile, just to run so perhaps you could compile in JBerries as a normal user and run the compiled class from the command line with sudo.

Re: Introducing JBerries

Posted: Sun Jan 12, 2014 3:36 pm
by suipaste
Yeah I managed to get it running on straight off the pi.
I think i'll do as you suggested and compile in jBerries and run through terminal as sudo.

I'm still very much in the early stages of properly understanding how to run/compile on the pi so I'm going to have to do some research in the mean time.

Thanks for your help!

--edit just found out I can run jBerries as sudo through Xming SSH using the gksudo command!

Re: Introducing JBerries

Posted: Sat Feb 01, 2014 11:24 pm
by Astrapicus
I downloaded the file and entered the command to install it but go the error: dpkg: error processing jberries-1.0.37.deb (--install): cannot access archive: no such file or directory errors were encountered while processing: jberries-1.0.37.deb
Anyone have a solution?

Re: Introducing JBerries

Posted: Sun Feb 02, 2014 9:37 am
by zeddex
Hi

The latest version is 1.0.43 - is this the version you downloaded? If so you need to install using the command:

Code: Select all

sudo dpkg -i jberries-bin-1.0.43.deb
Steve

Re: Introducing JBerries

Posted: Thu Nov 27, 2014 12:00 pm
by Robbi_Blechdose
Hello,
I have a problem: If I try to export my project, it says: Project exported successfully. But if I try to start the .jar, it just opens up with that Zip-Program (can't remember it's name) and I see: my 2 folders that I added to the classpath aren't there. And if I go to LXTerminal, navigate to the folder and try using my jar with the "java" command, it just tells me that it couldn't find a main class, but I specified it in JBerries. :cry:
I hope you can help me.

Robbi Blechdose

Re: Introducing JBerries

Posted: Sun Dec 07, 2014 7:10 pm
by zeddex
Hi

To run a jar file you need to add the '-jar' switch to the java command, e.g.:

Code: Select all

$ java -jar myjarfile.jar
Hope that helps.

Steve

Re: Introducing JBerries

Posted: Tue Dec 09, 2014 9:34 am
by gpio
If you need to add the classpath, you can use something:

$ java -jar --classpath .:/directory/'*' your.jar

Re: Introducing JBerries

Posted: Tue Dec 09, 2014 5:27 pm
by Robbi_Blechdose
Thank you!
But it still doesn't add my two folders I added (resources and libs) to the .jar file.

Robbi Blechdose

Re: Introducing JBerries

Posted: Wed Dec 10, 2014 4:55 pm
by zeddex
To add additional resources to the jar you need to first add them to the project. The simplest way to do this is to create the folders in the project 'src' directory and add them to the project using the project menu 'Include Files' option - select the folders in the selection dialog and click 'include'. Alternatively if the folders are located outside the project directory you can use the 'Import Files' option to add them to the project 'src' directory. Either way the extra folders must end up in the project 'src' directory and be included in the project (i.e. visible in the project tree view).

To include them in the jar export you must perform a build - the contents of the jar are determined by the files found in the project 'bin' folder; you must perform a build to populate the 'bin' folder with the class files and other project resources.

Re: Introducing JBerries

Posted: Wed Dec 10, 2014 5:39 pm
by Robbi_Blechdose
Thank you.
I have my folders outside the src folder and added to the classpath (it works that way), but if I want them in the jar,
I'll have to add them myself with XArchiver, right?

Robbi Blechdose

Re: Introducing JBerries

Posted: Wed Dec 10, 2014 5:47 pm
by zeddex
Yes. The jar exporter is designed to work with project resources only - anything outside the project will have to be added manually.