The Personal Blog of Todd Sharp

Creating Your First Website On Raspberry Pi

Posted By: Todd Sharp on 3/27/2017 10:42 GMT
Tagged: Grails, Groovy, Groovy On Raspberry Pi, Raspberry Pi

In this post we'll create and deploy a simple website on the Raspberry Pi.  There are a few prerequisites that I've covered in some previous posts - notably installing Grails and remotely deploying our code - so please refer to the previous posts in this series if you get stuck:

  • Part 1 
  • Part 2
  • Part 3
  • Part 4
  • Part 5
  • In the previous posts we had not yet installed Gradle on the Raspberry Pi, so before we get started, SSH into your Raspberry Pi and use SDKMAN to install Gradle:

    sdk install gradle

    Now lets create a new Grails project in IntelliJ IDEA on a machine other than your Pi (see this previous post).

    Make sure that the Grails version that you choose matches the version of Grails you've previously installed on your Pi.  (You did install it already, right?)

    When IntelliJ prompts you, go ahead and click Run 'create-app'.

    After your project has been created, if you've got Grails installed on your machine that you're developing on you can try grails run-app and see the application running on your local machine.  You won't be able to run it locally like this much longer since we'll be getting into GPIO integration and your local machine doesn't have any GPIO access!

    Set up a remote deployment server (see post 5) and after you've created the application, go to Tools - Deployment - Sync with Deployed...

    After you've synched up with the Pi, do a directory listing on the project directory on the Pi and you'll see all of the files that we just transferred. 

    At this point you should be set to run grails run-app on the Pi.  The first time it runs you'll notice quite a bit of dependencies need to be downloaded.  That'll only happen the first time you run the app.  Once the dependencies are downloaded, you'll get a message that the app is running:

    Grails application running at http://localhost:8080 in environment: development

    The localhost in this case refers to the Pi, so unless you're using VNC you won't be able to use localhost.  Instead, try:

    http://[Raspberry Pi IP]:8080

    And you should see:

    Woohoo!  You've now got a website up and running on the Pi!  The cool thing about our setup at this point is that Grails is running in development mode.  This means we can change code and Grails will compile and deploy the change on the fly.  Open up the view called index.gsp inside the /views directory and make a change to the text and see what happens.

    Image by jplenio from Pixabay

    Related Posts

    Simulating Texas Hold'em With Groovy

    Simulating Texas Hold'em With Groovy

    Last week I had a bit of free time and decided to see how difficult it would be to write a Texas Hold'em poker simulation in Groovy.  My goal wasn't...

    Spark Java "Flash" Scope

    Spark Java "Flash" Scope

    One of the handiest features of Grails is the "flash" scope.  The flash scope is "A temporary storage map that stores objects within the session for...

    Realtime GPIO On Raspberry Pi With Spark Java And WebSockets

    Realtime GPIO On Raspberry Pi With Spark Java And WebSockets

    One of the cooler things about the Spark Java framework is built in websocket support thanks to the embedded Jetty server.  I've long been fascinated...

    Note: Comments are currently closed on this blog. Disqus is simply too bloated to justify its use with the low volume of comments on this blog. Please visit my contact page if you have something to say!