GuidesJava
Quarkus REST API with Maven
Create a Java 21 Quarkus REST API with Quarkus REST, the Maven wrapper, JUnit 5, and REST Assured using Better Fullstack.
Use this stack when you want a Java REST service on Quarkus, with live reload in development and a Maven build that produces a runnable application.
npm create better-fullstack@latest my-quarkus-api -- \ --ecosystem java \ --java-web-framework quarkus \ --java-build-tool maven \ --java-orm none \ --java-auth none \ --java-api none \ --java-libraries none \ --java-testing-libraries junit5 rest-assuredWhat this creates
- A Maven project that imports the Quarkus 3 platform BOM and uses
quarkus-rest. - An
Applicationclass annotated with@QuarkusMain. - A
GreetingResourceatGET /hellothat returns plain text. quarkus-junit5, REST Assured, and one REST Assured test.- The Maven wrapper and a
.gitattributesfile that keeps wrapper scripts on the right line endings.
Generated shape
The Java package comes from the project name with separators removed, so my-quarkus-api uses com.example.myquarkusapi.
my-quarkus-api/
├── pom.xml
├── mvnw
├── mvnw.cmd
├── .mvn/wrapper/maven-wrapper.properties
├── .env.example
└── src/
├── main/java/com/example/myquarkusapi/
│ ├── Application.java
│ └── resource/GreetingResource.java
└── test/java/com/example/myquarkusapi/
└── RestAssuredHttpTest.javaNo src/main/resources/application.properties is generated. Quarkus runs on its defaults until you add one.
Prerequisites
- A JDK 21 installation. The
pom.xmlsetsmaven.compiler.releaseto 21. - No separate Maven install; use
./mvnw.
Run and verify
cd my-quarkus-api
./mvnw test
./mvnw quarkus:devDev mode serves the resource on port 8080 and recompiles on change:
curl http://localhost:8080/helloPackage the application with:
./mvnw packageRepresentative snippets
The resource reads an optional cors.origin value and sets the Access-Control-Allow-Origin header itself:
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public RestResponse<String> hello() {
String corsOrigin = ConfigProvider.getConfig()
.getOptionalValue("cors.origin", String.class)
.filter(value -> !value.isEmpty())
.orElse("*");
return RestResponse.ResponseBuilder.ok("Hello from my-quarkus-api")
.header("Access-Control-Allow-Origin", corsOrigin)
.build();
}
}MicroProfile Config maps the CORS_ORIGIN environment variable to cors.origin, and Quarkus also reads a .env file in the project root. Copy .env.example to .env to use the generated value locally.
Test against the Quarkus application
The generated RestAssuredHttpTest starts a JDK HttpServer with a stub /health route and checks it with REST Assured. It shows the REST Assured style but does not boot Quarkus or call GreetingResource. A @QuarkusTest exercises the real application:
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@QuarkusTest
class GreetingResourceTest {
@Test
void helloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(equalTo("Hello from my-quarkus-api"));
}
}quarkus-junit5 is already a test dependency, so this compiles without new packages.
When to choose it
Choose Quarkus for a Java service that should start fast and use Jakarta REST annotations with build-time processing. Choose Spring Boot with PostgreSQL and JPA when you need the persistence, security, and library options that Better Fullstack wires only for Spring Boot.
Compatibility notes
- Quarkus requires
--java-build-tool mavenorgradle. With Gradle, the project uses theio.quarkusGradle plugin and runs with./gradlew quarkusDev. --java-orm,--java-auth,--java-api, and--java-librariesare Spring Boot features. Set each tonone; when they are omitted, the CLI stops with "Spring-only Java features require the Spring Boot scaffold".--java-language kotlinis not available for Quarkus; the Kotlin scaffold covers Spring Boot and Ktor.- With
--java-testing-libraries junit5alone, the Quarkus template adds the dependency but no test file.rest-assured,mockito,wiremock,archunit,awaitility, andjqwikeach add a sample test;testcontainersandassertjadd none here.
Deployment notes
./mvnw package builds the Quarkus fast-jar layout under target/quarkus-app/. Run it with java -jar target/quarkus-app/quarkus-run.jar. No Dockerfile is generated for the Java ecosystem, so add one or use a platform buildpack, and set CORS_ORIGIN in that environment.
Troubleshooting
| Symptom | Check |
|---|---|
| CLI reports "Spring-only Java features" | Pass none for --java-orm, --java-auth, --java-api, and --java-libraries. |
Tests pass but /hello is untested | The generated test targets a stub server; add a @QuarkusTest. |
Access-Control-Allow-Origin is * | Set CORS_ORIGIN or cors.origin; the resource falls back to *. |
| CORS preflight requests fail | The resource sets one header on GET; enable quarkus.http.cors for full CORS handling. |
Next steps
- Open the Stack Builder.
- Read the Java ecosystem docs.
- Compare with Ktor API with Kotlin and Gradle.