Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
cache: maven

- name: Build with Maven
run: mvn -B clean package -Dquarkus.package.type=uber-jar
run: mvn -B clean package -Dquarkus.package.jar.type=uber-jar

- name: Create Release
id: create_release
Expand Down
90 changes: 57 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,84 @@
# java-nomad-example

This project uses Quarkus, the Supersonic Subatomic Java Framework.
Este es un ejemplo de cómo ejecutar el proyecto con Nomad con Java:

If you want to learn more about Quarkus, please visit its website: <https://quarkus.io/>.
* Descargando un compilado (que está en GitHub)
* Ejecutando desde local (que está en la carpeta `target`)

## Running the application in dev mode
## Descargando un compilado

You can run your application in dev mode that enables live coding using:
Se puede ejecutar el comando nomad con el task `java`, pero tiene la restricción que solo puede ejecutar archivos que sean descargados, no desde local:

```shell script
./mvnw quarkus:dev
```hcl
task "api" {
driver = "java"
#....
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at <http://localhost:8080/q/dev/>.
Por ello, se hizo un "[GH Actions](.github/workflows/release.yml)" que publica el .jar compilado en [GitHub](https://github.com/apuntesdejava/java-nomad-example/releases).

## Packaging and running the application
Finalmente, el nomad para ser ejecutado es este: [from-github.nomad](from-github.nomad), y comando es:

The application can be packaged using:

```shell script
./mvnw package
```shell
nomad run from-github.nomad
```

It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.
## Ejecutando desde local

The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.
Para ejecutar desde local, no se ejecuta el task `java` sino `raw_exec`.

If you want to build an _über-jar_, execute the following command:
1. Compilar el proyecto como uber-jar:

```shell script
./mvnw package -Dquarkus.package.jar.type=uber-jar
Bash:
```shell
./mvnw clean package -Dquarkus.package.type=uber-jar
```

The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.
Powershell:
```powershell
.\mwnw clean package "-Dquarkus.package.jar.type=uber-jar"
```

## Creating a native executable

You can create a native executable using:

```shell script
./mvnw package -Dnative
```

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
2. Con eso ya se tiene el .jar compilado, ahora, ejecutamos el nomad, pero para ello necesitamos pasar la posición del jar.
Por ello, el archivo [`from-local.nomad`](from-local.nomad) tiene la definición de un parámetro de entrada

```hcl
variable "jar_path" {
type = string
description = "Ruta absoluta al JAR en la máquina host"
}

```shell script
./mvnw package -Dnative -Dquarkus.native.container-build=true
```

You can then execute your native executable with: `./target/java-nomad-example-1.0-SNAPSHOT-runner`
Y en la parte donde va el .jar, se indica esa variable:

```hcl
task "api" {
driver = "raw_exec"
config {
command = "java"
args = [
"-jar",
var.jar_path # Aquí va la variable
]
}
}
```

If you want to learn more about building native executables, please consult <https://quarkus.io/guides/maven-tooling>.
Finalmente, para ser ejecutado, se hace de la siguiente manera:

## Related Guides
Bash (Linux/macOS):

```shell
nomad job run -var="jar_path=$(pwd)/target/java-nomad-example-runner.jar" from-local.nomad
```

Powershell (Windows)
```powershell
nomad job run -var="jar_path=$(Get-Location)\target\java-nomad-example-runner.jar" .\from-local.nomad
```

- REST JSON-B ([guide](https://quarkus.io/guides/rest#json-serialisation)): JSON-B serialization support for Quarkus
REST. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on
it.
La variable `$(pwd)` en bash y la variable `$(Get-Location)` en PowerShell dan la ruta absoluta desde donde se está ejecutando el comando. Por ello se está concatenando la parte de `target` y el jar generado, a fin de no colocar un hardcode de la ruta absoluta.
23 changes: 23 additions & 0 deletions from-github.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
job "from-github" {
datacenters = ["dc1"]
group "backend" {
count = 1
network {
port "http" {
static = 8080
}
}
task "api" {
driver = "java"
artifact {
source = "https://github.com/apuntesdejava/java-nomad-example/releases/download/2/java-nomad-example-runner.jar"
destination = "local"
}
config {
jar_path = "local/java-nomad-example-runner.jar"
}

}
}

}
29 changes: 29 additions & 0 deletions from-local.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "jar_path" {
type = string
description = "Ruta absoluta al JAR en la máquina host"
}

job "from-local" {
datacenters = ["dc1"]


group "backend" {
count = 1
network {
port "http" {
static = 8080
}
}
task "api" {
driver = "raw_exec"
config {
command = "java"
args = [
"-jar",
var.jar_path
]
}
}
}

}