본문 바로가기

개발

라즈베리 파이에서 글래스피시 구동 - GlassFish 4 on the Raspberry Pi

글래스피시(GlassFish)는 Java EE 기반 웹 애플리케이션 서버(WAS)입니다.

이 글래스피시를 라즈베리 파이에서 구동하는 방법을 기재하였습니다.

GlassFish 4 on the Raspberry Pi
By reza_rahman on Apr 28, 2014

For those that remember the very early days of Java, the language was conceived with embedded systems in mind (anyone still remember the concept of Java powered toasters?). While as far fetched as that seemed at the time the emerging field of the Internet of Things (IoT) and Machine-to-Machine (M2M) communication is promising to finally make that dream a reality. It may or may not also surprise you that Java EE has a key part to play in this area as you need many of the Java EE services in order to use embedded devices effectively. Fortunately modern Java EE application servers like GlassFish can run well on very small embedded platforms like the Raspberry Pi (if you still live in the "J2EE era" this probably also seems like science fiction).

Oracle's own Mark Heckler has a very well written and maintained blog post on how to do this almost from scratch. If you are an IoT and GlassFish enthusiast it is an excellent resource worth checking out.

http://www.thehecklers.org/2013/10/27/glassfish4-raspberrypi/


Quick & Dirty How-to Guide: Install GlassFish 4 on Raspberry Pi
Category: IoT/Embedded, Java, Technology

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.  :-D
Document version 1.2 (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.