I’ve been testing various “embedded platforms” lately to provide infrastructure for my IoT configurations. In doing so, I’ve installed and configured the GlassFish 4 Web Profile to run successfully on the Raspberry Pi Model B (512M). This post is not meant to be exhaustive or even necessarily prescriptive, but rather an iterative log of what I’ve done and do to configure a Raspberry Pi to “run with the big dogs”, i.e. Java Enterprise Edition (EE) 7.
Please check back (or subscribe to my RSS feed for IoT) to monitor updates. The Internet of Things (IoT) is a very dynamic space and will likely remain so for some time! The only constant…is change. 😀
Document version 1.3 (This number will change as I make updates and is for reference only)
Steps to Install/Configure GlassFish 4 on the Raspberry Pi
- Download the latest version of Raspbian Wheezy from here. You can install NOOBS, Arch, or some other distro, but I chose Raspbian. Note that this distro includes the Java SE 7 JDK, which simplifies things a bit. If you wish to use an previous Raspbian build that doesn’t already include the JDK, simply run “sudo apt-get update && sudo apt-get install oracle-java7-jdk” from your Pi shell.
- Make a bootable SD card by doing the following (on my Mac; Windows steps will vary a bit):
- Unzip/decompress the downloaded image from step 1
- Open a Mac terminal window
- Run “diskutil list” to see drives
- Plug SD card into SD card slot
- Again run “diskutil list” to see drives, now including the SD card
- Run “sudo diskutil unmountDisk /dev/diskn“, where n is the disk number of the SD card (as reported by diskutil)
- Issue the following command, being very careful to ensure the of= parameter points to the SD card! If not, you can overwrite something you’d rather not…like your boot drive: “sudo dd if=<path/name_of_Raspbian_image.img> of=/dev/diskn bs=1m”
- Once dd completes, issue “diskutil eject /dev/diskn” to eject the SD card
- Plug the SD card into the Pi, plug ethernet cable and power into the Pi to boot.
- At this point, you’ll need to determine current (dynamic) IP address of the Pi. I plugged in my Atrix Lapdock and did this “on the Pi”, but you can also use nmap or connect it to HDMI (TV) and USB keyboard.
- Run “sudo raspi-config” and set the following:
- Expand the file system to take the entire SD card (not just what the image initially does)
- Under Internationalisation Options, change Locale, Timezone, & Keyboard layout as desired
- Overclock to High (950MHz). I’ve tried Turbo, but it seems prone to flakiness & data loss…at least for me.
- Under Advanced Options, change Hostname to desired Pi name, Memory Split to 16 (as a server, we can skinny the GPU memory allocation to maximize “main” memory), and enable SSH. You can also “Update this tool” (raspi-config) to the latest version, never a bad thing.
- Select “Finish” to reboot the Pi & use the new settings
- Ensure the Pi has a static IP by doing the following (recommended for any server):
- Run “ifconfig -a” and “netstat -nr” on the Pi to gather the following information: current IP (if you want to keep it), netmask, gateway, destination, and broadcast. Jot these down.
- Make a backup of /etc/network/interfaces by running “sudo cp /etc/network/interfaces /etc/network/interfaces.orig
- Modify the interfaces file. I used vi, but use whatever editor you can & are comfortable with! The vi syntax is “sudo vi /etc/network/interfaces”
- Change the line that reads “iface eth0 inet dhcp” to “iface eth0 inet static” and add the following lines:
- address 192.168.1.nnn (this is the IP address you want the Pi to have & keep)
- netmask 255.255.255.0 (or whatever was shown in ifconfig -a above)
- network 192.168.1.0 (or whatever was in the destination column, 2nd line from netstat -nr above)
- broadcast 192.168.1.255 (as shown in ifconfig -a)
- gateway 192.168.1.1 (or what was shown in either ifconfig or netstat)
- Save the file
- Reboot the Pi (“sudo reboot”)
- NOTE: You’ll also need to tell your network DHCP device/router that the IP address you statically assigned to the Pi is off-limits for assigning to another device
- Download GlassFish 4 Web Profile (or full EE platform) from here. I chose the Zip installer.
- Copy the GlassFish .zip file to the Pi (“scp glassfish-4.0-web.zip pi@raspi:.”). I have an entry in my Mac’s /etc/hosts that points “raspi” to the Pi’s static IP address.
- On the Pi, “install” GlassFish by doing the following:
- Run “sudo mkdir -p /app/glassfish” to create GlassFish app parent directory
- Run “sudo chown pi /app/glassfish” to assign directory ownership to the pi user. Not absolutely necessary, but you typically don’t want root to own everything (although honestly at this stage & for this install, it’s not critical)
- “cd /app/glassfish” as the pi user to change directories into the “install” directory
- Run “unzip ~/glassfish-4.0-web.zip” to extract the GF files into this directory
- Now to configure GF to allow for remote administration/configuration using its web console app:
- “cd /app/glassfish/glassfish4/bin”
- Run “
./asadmin change-admin-password --user admin
” to assign a password to the admin user. The admin password defaults to a blank password, a no-no for GF remote admin. - Run “./asadmin start-domain” to start the default domain (which comes preconfigured in GF)
- Run “./asadmin enable-secure-admin” to enable remote administration using the web console
- In order to take utilize remote admin, stop the domain by running “./asadmin stop-domain”, then…
- Start the domain once more with “./asadmin start-domain”
- From your workstation/laptop, plug this into a browser address bar: “raspi:4848” (substituting the name of your Pi per your /etc/hosts file) or “192.168.1.n:4848″ (substituting the IP address or your Pi) to load the GF admin console
- Login and relish the fact that you now have a full Java EE 7 stack (or web profile) running on your Raspberry Pi server!
I’m capturing this from memory, so it’s possible I’ve missed a step I performed or have related it not-exactly-perfectly…but if you spot something that isn’t quite right or have questions, please let me know! I’ll update this document accordingly. YMMV (Your Mileage May Vary), especially if you’re using a Linux or Windows machine for your workstation, but hopefully, this will get you that much closer to your own tiny Java EE 7 stack for your own growing IoT empire.
All the best,
Mark
P.S. – Follow me on Twitter at @MkHeck for more Java/IoT adventures…yours and mine (and ours)!
Related Posts:
Tags: configure, GlassFish, GlassFish4, install, Internet of Things, IoT, java, JavaEE, JavaEE7, Pi, Raspberry, Raspberry Pi, Web Profile
its ./asadmin enable-secure-admin
Ack, typo! Good catch, and thank you for pointing it out! It’s fixed now. 🙂
All the best,
Mark
[…] http://www.thehecklers.org/2013/10/27/glassfish4-raspberrypi/ […]
Web version is working slowly but fine, but the full-stack version is too heavy for my poor raspberry.
Hi JB,
I can relate. Expectations for the Pi as a platform are dramatically different from those you’d have for a “normal” app server…but still very serviceable for the right use cases. Good luck, and please share your results as you continue to experiment!
Cheers,
Mark
Have you managed to get the update tool working?
Hi Ian,
I haven’t had any problems with updates…what problems are you encountering?
Cheers,
Mark
Hi Mark, thanks for replying. Easiest to just show what happens:
gf@raspberrypi /opt/glassfish4/bin $ ./updatetool
The software needed for this command (updatetool) is not installed.
If you choose to install Update Tool, your system will be automatically
configured to periodically check for software updates. If you would like
to configure the tool to not check for updates, you can override the
default behavior via the tool’s Preferences facility.
When this tool interacts with package repositories, some system information
such as your system’s IP address and operating system type and version
is sent to the repository server. For more information please see:
http://wikis.oracle.com/display/updatecenter/UsageMetricsUC2
Once installation is complete you may re-run this command.
Would you like to install Update Tool now (y/n): y
Exception in thread “main” java.lang.NullPointerException
at com.sun.pkg.client.SystemInfo.getCanonicalOSArch(SystemInfo.java:144)
at com.sun.pkg.client.Image.loadConfig(Image.java:1313)
at com.sun.pkg.client.Image.(Image.java:1048)
at com.sun.pkg.client.Client.main(Client.java:101)
Unrecognized exception: null
java.lang.NullPointerException
at com.sun.pkg.client.SystemInfo.getCanonicalOSArch(SystemInfo.java:144)
at com.sun.pkg.client.Image.loadConfig(Image.java:1313)
at com.sun.pkg.client.Image.(Image.java:1048)
at com.sun.pkg.client.Image.(Image.java:1026)
at com.sun.pkg.bootstrap.Bootstrap._main(Bootstrap.java:195)
at com.sun.pkg.bootstrap.Bootstrap._main(Bootstrap.java:163)
at com.sun.pkg.bootstrap.Bootstrap.main(Bootstrap.java:113)
So you don’t see this?
Cheers,
Ian.
Ah, the GlassFish update tool! I don’t use it on the Pi; when I need to change something out, I effectively start fresh by building a new platform on a new SD card: restoring from an SD backup to the new card and then replacing GF/JDK/etc., migrating data/settings/apps, & just plugging it in. That allows me to deploy new everything periodically and have the original config as a backup. Once I confirm everything works properly, I make a backup of the new config and just repurpose the old SD card for another Pi deployment. I keep a small stack of them. 😀
That said, I think what you’re running into is a lack of (full, unequivocal) support for Raspbian in some way…it might be a simple fix, but since the GF team will likely never test on the Pi as a strategic platform…
It’s a good question, and it would be nice to have that working. I won’t be able to play with that much until after JavaOne, but I’m adding it to my “research list” now, and if I figure anything out, I’ll definitely share it. Please do the same if you get there first!
Thanks for the note, Ian, and good luck!
Cheers,
Mark
OK, so it’s not just me then! I haven’t actually needed any updates to this point, and everything else appears to be working, if a little slowly 😉 I’ve got the duke’s tutoring example (from the Java EE tutorial) running, and that’s fine, apart from a JSF bug that means you have to click buttons twice to make then operate. But it’s just a bi t of fun 😉
Cheers, Ian.
It’s just
./asadmin change-admin-password
It can’t take parameters, but will ask you for the current username and password.
Hi Marcel,
It actually can take parameters, but WordPress converted my two hyphens to one (long) dash, making it fail to work properly. 🙁 The syntax to feed the username into that command is:
./asadmin change-admin-password --user admin
Here’s hoping that comes through correctly this time, but if not, what should precede “user” is two hyphens. 😀
Thanks for the heads-up!
Mark
Of course, I must have simply copy-pasted it.
One more addition: earlier I installed Tomcat using the steps in https://tommorrisblog.wordpress.com/2015/06/22/installing-apache-tomcat-8-on-a-raspberry-pi/ and now I created a service file called glassfish in /etc/init.d that looks like . Then I issued
sudo update-rc.d glassfish defaults
and now GlassFish starts every time I reboot my Pi.
The link to my pastebin was eaten by WordPress. It is https://ptpb.pw/mMzD