Simplifying Jakarta EE Development with JBang and Payara Micro

Photo of Luqman Saeed by Luqman Saeed

What is JBang?

JBang is a tool that lets you run Java code with zero build setup. It handles dependencies, compilation, and execution with a single command - making Java as easy to run as a script. With JBang, you can:

  • Run Java programs without setting up a project structure
  • Declare dependencies directly in your Java file
  • Execute Java applications with a single command
  • Use Java for scripting without the typical overhead

For us Jakarta EE developers, JBang eliminates many of the configuration steps that typically slow down development. This post explores how to use a pre-configured JBang catalog with Payara tools hosted at https://github.com/pedanticdev/jbang-catalog to streamline your Jakarta EE development.

Advantages of JBang for Jakarta EE Development

Traditional Jakarta EE development often involves:

  • Setting up a Maven or Gradle project
  • Managing dependencies and application servers
  • Lengthy build-deploy-test cycles

JBang simplifies this process by letting you focus on your code rather than build configuration. For Payara Micro specifically, JBang eliminates the need to download JAR files manually and remember complex command-line options.

Understanding JBang Aliases and Catalogs

JBang's power comes from its alias and catalog system. As the JBang documentation explains:

To avoid remembering long paths and to enable easy launch of jbang scripts there is an alias command to setup and manage aliases to actual scripts.

An alias acts as a shortcut to a Java script, Maven artifact, or Git repository. For example:

jbang alias add --name hello https://github.com/jbangdev/jbang-examples/blob/HEAD/examples/helloworld.java

This command adds an alias named hello pointing to the specified GitHub URL, which you can then run with:

jbang hello

Catalogs take this further by allowing you to share collections of aliases across teams and projects - perfect for standardizing Jakarta EE tooling.

Creating a Payara Micro Alias

Following the same pattern, we can create an alias for Payara Micro:

jbang alias add --name micro fish.payara.extras:payara-micro:6.2025.2

Now you can start Payara Micro with a simple command:

jbang micro

Working with Catalogs

While local aliases are useful, JBang's true power comes from its catalog system. Catalogs allow you to share sets of aliases across teams and projects.

Implicit Alias Catalogs

JBang supports "implicit catalogs" that follow a special format, making it easy to access remote catalogs without explicit setup. For example:

Using the Ready-Made Jakarta EE Catalog

There's already a dedicated catalog for Jakarta EE development with Payara tools available at https://github.com/pedanticdev/jbang-catalog . The catalog contains:

{
 "catalogs": {},
 "aliases": {
   "pcl": {
     "repositories": ["payara=https://nexus.payara.fish/repository/payara-artifacts"],
     "script-ref": "fish.payara.cloud:pcl:1.1.0",
     "description": "pcl is command line utility for managing Payara Cloud namespaces and applications."
   },
   "micro": {
     "script-ref": "fish.payara.extras:payara-micro:6.2024.10",
     "description": "Payara Micro is an embedded release of Payara built from the Payara Embedded Web release. It allows you to deploy and run WAR files from the command line with a single command, and also features automatic, dynamic clustering with Hazelcast."
   }
  },

 "templates": {}
}

To add this catalog to your JBang installation:

jbang catalog add --name payara https://github.com/pedanticdev/jbang-catalog/blob/main/jbang-catalog.json

Or use the implicit catalog format:

jbang catalog add --name payara pedanticdev/jbang-catalog

Using the Payara Catalog

Now you can access the aliases in the catalog:

# List all aliases in the catalog
jbang alias list payara

# Run Payara Micro
jbang micro@payara

# Deploy a WAR file
jbang micro@payara --deploy myapp.war

# Use Payara Cloud CLI
jbang pcl@payara namespace list

As the JBang documentation notes:

In fact, it's possible to run the alias just by using jbang run hello, the @demo part is only necessary when trying to disambiguate between aliases with the same name from different catalogs.

Benefits of this Approach

  1. Simplified Setup: No need to manually download or configure Payara Micro
  2. Consistency: Everyone on your team uses the same versions and configurations
  3. Discoverability: Catalogs make it easy to find and use common tools
  4. Versioning: You can update aliases centrally when new versions are released

Team Collaboration

For team settings, you have two options:

  1. Host your catalog on a website or git repository and share the URL
  2. Create a local jbang-catalog.json in your project repository

JBang will search for catalog files in multiple locations:

  1. Current directory: ./jbang-catalog.json
  2. In ./.jbang/jbang-catalog.json
  3. Parent directories (recursively)
  4. User home: $HOME/.jbang/jbang-catalog.json

This allows you to have project-specific catalogs that customize the Jakarta EE environment for each project.

Examples with the Payara Catalog

Let's look at some practical examples of how to use the Payara catalog:

Running Payara Micro

# Start Payara Micro with default settings
jbang micro@payara

# Start with custom port
jbang micro@payara --port 9090

Deploying Applications

# Deploy a WAR file
jbang micro@payara --deploy myapp.war

# Deploy with context root
jbang micro@payara --deploy myapp.war --contextroot app

Managing Payara Cloud

# List namespaces
jbang pcl@payara namespace list

# Create a new namespace
jbang pcl@payara namespace create my-project

# Deploy an application to Payara Cloud
jbang pcl@payara deploy my-app myapp.war

# List deployed applications
jbang pcl@payara app list


Conclusion

JBang's alias and catalog features, with this pre-configured Payara catalog, can create a simplified Jakarta EE development workflow that's easy to set up, share, and maintain. This approach reduces the friction of Jakarta EE development without sacrificing its power and flexibility.

Start using JBang with the Payara catalog today to simplify your Jakarta EE development process!

Related Posts

Comments