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).
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.
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...
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...
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...