BT

InfoQ Homepage News Quarkus 1.5 Features New Extensions and fast-jar Packaging

Quarkus 1.5 Features New Extensions and fast-jar Packaging

Lire ce contenu en français

Bookmarks

Red Hat has released Quarkus 1.5, featuring new extensions to support Picocli, gRPC, MicroProfile GraphQL, various Amazon services, and Hibernate ORM with Panache. There is also a new fast-jar packaging format and a Spring Cache compatibility layer.

Dubbed "Supersonic Subatomic Java," Quarkus, a portmanteau of "quark" and "us," was first introduced in March 2019 as a full-stack, Kubernetes-native, Java framework designed for GraalVM and OpenJDK HotSpot. Quarkus is crafted from well-known Java libraries and standards such as MicroProfile, Vert.x, CDI, JAX-RS, Hibernate and Netty, just to name a few. In just eight months after its debut, Quarkus 1.0 was released in November 2019.

In his blog post to officially introduce Quarkus, Jason Greene, Quarkus co-founder, distinguished engineer and manager at Red Hat, discussed how Java can be a leader in the cloud-native environment, writing:

The goal of Quarkus is to make Java a leading platform in Kubernetes and serverless environments while offering developers a unified reactive and imperative programming model to optimally address a wider range of distributed application architectures.

We will explore some of these new features in this article.

As an alternative to traditional JAR packaging, the new fast-jar packaging format was designed to provide faster startup times. As an experimental feature at this time, fast-jar is not invoked by default. To do so, the following statement may be added to an application.properties configuration file:

    
quarkus.package.type=fast-jar
    

An alternative approach is to execute the Maven command:

    
$ mvn package -Dquarkus.package.type=fast-jar
    

The new command mode, recently introduced in Quarkus 1.4, allows developers to write applications such as command-line clients, batch scripts and console apps to run without a REST endpoint. Quarkus 1.5 now supports Picocli, a Java library and mini-framework for creating rich command-line applications.

Considered an experimental feature at this time, the Picocli extension may be added to an existing Quarkus 1.5 application by executing the following Maven command:

    
$ mvn quarkus:add-extension -Dextensions="picocli"
    

This will add a new dependency to the pom.xml file:

    
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-picocli</artifactId>
</dependency>
    

To see how this works, consider the following example:

    
@CommandLine.Command
public class HelloCommand implements Runnable {

    @CommandLine.Option(names = {"-n", "--name"}, description = "Who will we greet?", defaultValue = "World")
    String name;

    private final GreetingService greetingService;

    public HelloCommand(GreetingService greetingService) {
        this.greetingService = greetingService;
        }

    @Override
    public void run() {
        greetingService.sayHello(name);
        }
    }

@Dependent
class GreetingService {
    void sayHello(String name) {
        System.out.println("Hello " + name + "!");
        }
    }
    

The HelloCommand class implements the Runnable interface and is decorated by the @CommandLine.Command annotation. The instance variable, name, is decorated by the @CommandLine.Option annotation to define command-line parameters, a description and a default value.

As shown in the screenshot below, the command-line application is executed using the default value of "World" to print "Hello World!" in the terminal window upon executing the Maven command:

    
$ mvn clean compile quarkus:dev
    

The defined command-line parameters, -n or --name, may be used to override the default value of "World" by using one of these Maven commands:

    
$ mvn clean compile quarkus:dev -Dquarkus.args="-n Mike"
$ mvn clean compile quarkus:dev -Dquarkus.args="--name=Mike"
    

This will print "Hello Mike!" in the terminal window.

GraphQL, an open-source data query and manipulation language for APIs, was a recent addition to the MicroProfile family as a standalone API with the recent release of MicroProfile GraphQL 1.0 specification. Implemented by SmallRye, Quarkus 1.5 provides an extension to build GraphQL applications with Quarkus.

Similar to the Picocli extension, the GraphQL extension may be added to an existing Quarkus 1.5 application by executing the Maven command:

    
$ mvn quarkus:add-extension -Dextensions="graphql"
    

This will add a new dependency to the pom.xml file:

    
<dependency>
    <groupId>io.quarkus</groupId$gt;
    <artifactId>quarkus-smallrye-graphql</artifactId>
</dependency>
    

The Quarkus GraphQL guide provides examples and detailed information on how to get started.

Now celebrating its 25th birthday, Java was not originally designed for a cloud-native environment. As the cloud-native and microservices era has emerged over the past few years, frameworks such as Quarkus, MicroProfile, Helidon and Micronaut have enabled Java to be a leader in the cloud-native, microservices and serverless environments.

Resources

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Typo

    by Popma Remko /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Nice article!
    One small thing: the first sentence misspelled “Picocli” as “Picoli”.

  • Re: Typo

    by Michael Redlich /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hi Popma:

    Thanks for your feedback! I certainly appreciate it! And thanks for catching the typo. I just fixed it.

    Mike.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.