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:

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