Skip to content

A basic demo project that shows how to use Rocker with Micronaut 3

License

Notifications You must be signed in to change notification settings

andbin/micronaut3-rocker-basic-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java 11 Micronaut 3.9.4 Built with Apache Maven MIT License

Micronaut 3 – Rocker Basic Demo

This is a basic demo project that shows how to use Rocker (a template engine for Java) with Micronaut 3.

License

This project is released under the MIT License, a very permissive free software license.

See the full text of the license: LICENSE.txt

How to build and run the application

You can build and run the application in different ways (depending on your environment and/or IDE).

1) Using Maven to build a “shaded” JAR that is easy to run

From command line (in project's main directory):

  • run mvn package
  • go into the target/ directory
  • run java -jar micronaut3-rocker-basic-demo.jar

2) Using Maven to directly build&run the application

From command line (in project's main directory):

  • run mvn mn:run

3) Using the Eclipse IDE

IMPORTANT: Micronaut makes use of annotation processing, so in Eclipse you need to have the m2e-apt. If you don't have it (or if you are not sure):

  • open the marketplace (“Help” -> “Eclipse Marketplace...”)
  • search: m2e-apt (you should find: m2e-apt X.Y.Z where X.Y.Z is a version number)
  • if the button on the right shows “Installed”, you already have it. Otherwise, install it
  • in any case (especially after the m2e-apt installation), check the global preferences (“Window” -> “Preferences”), section “Maven” -> “Annotation Processing” and ensure that the option “Automatically configure JDT APT ( ..... )” is checked

Then:

  • import the project (“File” -> “Import...” then “Existing Maven Projects” etc...)

WARNING: Rocker generates a Java source code for each template file. This is performed by the rocker-maven-plugin. When you import the project, Eclipse will complain that “No marketplace entries found to handle rocker-maven-plugin:X.Y.Z:generate in Eclipse.”. Ignore this error (there's nothing you can do to resolve, for what I know), keep “Resolve Later” and finish the import procedure.

You will have an error in HomeController.java. This is normal since Eclipse didn't process the template file using the rocker-maven-plugin. You have to manually execute the generate-sources phase by:

  • running mvn generate-sources in project's main directory
  • or using the command “Run As” -> “Maven generate-sources” in Eclipse

Then do a “Refresh” of the project in Eclipse. The error in HomeController.java should be resolved.

  • build the project (if “Build Automatically” is not active)
  • locate the Micronaut3RockerBasicDemoApp class and then “Run As” -> “Java Application”

Note: other IDEs may be used, however you must carefully check if and how the IDE uses annotation processing.

How to use the application

Once the application is running, point your preferred browser to http://localhost:8080. You should see a simple page showing some version informations.