<commit_before>////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
////
= Quarkus - Scripting with Quarkus
include::./attributes.adoc[]
:extension-status: preview

Quarkus provides integration with https://jbang.dev[jbang] which allows you to write Java scripts/applications requiring no Maven nor Gradle to get running.

In this guide, we will see how you can write a REST application using just a single Java file.

include::./status-include.adoc[]

== Prerequisites

To complete this guide, you need:

* less than 5 minutes
* https://jbang.dev/download[jbang v0.40.3+]
* an IDE
* GraalVM installed if you want to run in native mode

== Solution

Normally we would link to a Git repository to clone but in this case there is no additional files than the following:

[source,java,subs=attributes+]
----
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus:quarkus-resteasy:{quarkus-version}
//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager

import io.quarkus.runtime.Quarkus;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.logging.Logger;

@Path("/hello")
@ApplicationScoped
public class quarkusapp {

    @GET
    public String sayHello() {
        return "hello";
    }

    public static void main(String[] args) {
        Quarkus.run(args);
    }

    @Inject
    GreetingService service;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/greeting/{name}")
    public String greeting(@PathParam String name) {
        return service.greeting(name);
    }

    @ApplicationScoped
    static public class GreetingService {

        public String greeting(String name) {
            return "hello " + name;
        }
    }
}
----

== Architecture

In this guide, we create a straightforward application serving a `hello` endpoint with a single source file, no additional build files like `pom.xml` or `build.gradle` needed. To demonstrate dependency injection, this endpoint uses a `greeting` bean.

image::getting-started-architecture.png[alt=Architecture]

== Creating the initial file

First, we need a Java file. jbang lets you create an initial version using:

[source,shell,subs=attributes+]
----
jbang scripting/quarkusapp.java
cd scripting
----

This command generates a .java file that you can directly run on Linux and macOS, i.e. `./quarkusapp.java` - on Windows you need to use `jbang quarkusapp.java`.

This initial version will print `Hello World` when run.

Once generated, look at the `quarkusapp.java`.

You will find at the top a line looking like this:

[source,java]
----
//usr/bin/env jbang "$0" "$@" ; exit $?
----

This line is what on Linux and macOS allows you to run it as a script. On Windows this line is ignored.

The next line

[source,java]
----
// //DEPS <dependency1> <dependency2>
----

Is illustrating how you add dependencies to this script. This is a feature of `jbang`.<commit_msg>Missing 'init' parameter added<commit_after>////
This guide is maintained in the main Quarkus repository
and pull requests should be submitted there:
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc
////
= Quarkus - Scripting with Quarkus
include::./attributes.adoc[]
:extension-status: preview

Quarkus provides integration with https://jbang.dev[jbang] which allows you to write Java scripts/applications requiring no Maven nor Gradle to get running.

In this guide, we will see how you can write a REST application using just a single Java file.

include::./status-include.adoc[]

== Prerequisites

To complete this guide, you need:

* less than 5 minutes
* https://jbang.dev/download[jbang v0.40.3+]
* an IDE
* GraalVM installed if you want to run in native mode

== Solution

Normally we would link to a Git repository to clone but in this case there is no additional files than the following:

[source,java,subs=attributes+]
----
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus:quarkus-resteasy:{quarkus-version}
//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager

import io.quarkus.runtime.Quarkus;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
import org.jboss.logging.Logger;

@Path("/hello")
@ApplicationScoped
public class quarkusapp {

    @GET
    public String sayHello() {
        return "hello";
    }

    public static void main(String[] args) {
        Quarkus.run(args);
    }

    @Inject
    GreetingService service;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/greeting/{name}")
    public String greeting(@PathParam String name) {
        return service.greeting(name);
    }

    @ApplicationScoped
    static public class GreetingService {

        public String greeting(String name) {
            return "hello " + name;
        }
    }
}
----

== Architecture

In this guide, we create a straightforward application serving a `hello` endpoint with a single source file, no additional build files like `pom.xml` or `build.gradle` needed. To demonstrate dependency injection, this endpoint uses a `greeting` bean.

image::getting-started-architecture.png[alt=Architecture]

== Creating the initial file

First, we need a Java file. jbang lets you create an initial version using:

[source,shell,subs=attributes+]
----
jbang init scripting/quarkusapp.java
cd scripting
----

This command generates a .java file that you can directly run on Linux and macOS, i.e. `./quarkusapp.java` - on Windows you need to use `jbang quarkusapp.java`.

This initial version will print `Hello World` when run.

Once generated, look at the `quarkusapp.java`.

You will find at the top a line looking like this:

[source,java]
----
//usr/bin/env jbang "$0" "$@" ; exit $?
----

This line is what on Linux and macOS allows you to run it as a script. On Windows this line is ignored.

The next line

[source,java]
----
// //DEPS <dependency1> <dependency2>
----

Is illustrating how you add dependencies to this script. This is a feature of `jbang`.
{'fraction_non_alphanumeric': 0.1067242442936459, 'fraction_numerical': 0.0027760641579272056, 'mean_word_length': 3.6755587599134825, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1770681', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1948, 'n_words': 693}