Why? Sometimes you may not have access to various resources in environments in order to encapsulate all of the dependencies of your :”script” (DISCLAIMER: You’re now basically making a full blown groovy/java project). But this could also be handy if you’ve written a groovy script and want to make it into a full blown application.

In order to do this we go to: https://start.spring.io/ and generate the project, you’ll now have something like:

Spring Initializr

extract the downloaded zip file to a directory and explore the contents:

In order to keep the application up I have decided to use a web context for spring boot, so our jar will run tomcat emedded. And I have also aligned the dependencies so the project is using the redhat blessed jars for camel/fuse/springboot. Importing a maven bom does not seem to be possible using the @Grab groovy grapes. Hence why I am trying this in gradle.

Modify the build.gradle like so:

And also modify the src/main/groovy/SomescriptsApplication.groovy to include a set of camel routes. An IDE like IntelliJ or Eclipse would help in order to resolve the import statements. We have had to modify aspects of what we would be doing in a groovy script.

Running the application from gradle with ./gradlew bootRun will confirm the camel context is using the specified fuse version 2.21.0.fuse-720050-redhat-00001

And we can confirm that the project is using the Red Hat Fuse dependencies by running ./gradlew dependencies

In order to create a fat spring-boot jar we run ./gradlew bootjar

We can now see that a build has been generated with a somescripts-0.0.1-SNAPSHOT.jar

This jar is now portable and should run anywhere with java 8 by running java -jar ${jarfile} as below:

You should also be able to confirm that the REST service is available with curl

Asciinema

References


codergists