DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Evolution of Recommendation Systems: From Legacy Rules Engines to Machine Learning
  • Okta + SAML + JBoss EAP 6.4.x + Picketlink

Trending

  • Segmentation Violation and How Rust Helps Overcome It
  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • How to Configure and Customize the Go SDK for Azure Cosmos DB
  • Why Documentation Matters More Than You Think
  1. DZone
  2. Coding
  3. Java
  4. Hello World With JBoss Modules

Hello World With JBoss Modules

There aren't a lot of examples of JBoss Modules out there, so let's create a simple Hello World program.

By 
Anton Arhipov user avatar
Anton Arhipov
·
Oct. 11, 16 · Tutorial
Likes (15)
Comment
Save
Tweet
Share
21.1K Views

Join the DZone community and get the full member experience.

Join For Free

JBoss Modules is quite an interesting project that powers JBoss application server and some other projects in the JBoss ecosystem. However, I was surprised to find out that there isn't much you can find about Modules on the webs. Documentation is... bad half-done, not that many tutorials exist, and no good examples of how you could use this awesome library in your project. The best you can find is the description on how to apply JBoss Modules within the application server. (sad panda)

I was looking for the simplest "Hello World" example and couldn't find it. Well, why not create one myself then? 

Downloading JBoss Modules

A surprising fact is that you won't find JBoss Modules in the list of upstream projects at jboss.org. 

The first option is to download the jboss-modules.jar from Bintray or Maven Central. And the second option is to build it from sources. 

Oh, OK, one more option (not the best one) is to download the application server that includes jboss-modules.jar, e.g. WildFly.

Hello World

Ahh, the good old "Hello World" :) The main application class is as follows:

public class Main {
    public static void main(String[] args) {
        new Hello().say();
    }
}


So we have a dependency, the Hello class, that will reside in a different module:

public class Hello {
    public void say() {
        System.out.println("Hello!");
    }
}


So to mimic the modules we first have to compile both classes and assemble corresponding JARs. Plus, a proper directory layout is expected by JBoss Modules to resolve the artifacts.

The main class belongs to the 'app' module, and Hello class belongs to the 'hello' module. Each module requires module.xml descriptor. This part is somewhat documented actually. Also the 'main' directory that you see within each module's directory structure is actually a version (!). 

A version slot identifier is an arbitrary string; thus one can use just about any system they wish for organization.  If not otherwise specified, the version slot identifier defaults to "main".

Here's the module.xml for the app module:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="app">
    <main-class name="Main"/>

    <resources>
        <resource-root path="main.jar"/>
    </resources>

    <dependencies>
        <module name="hello"/>
    </dependencies>
</module>

It specifies the main class (i.e. Main), the reference to the actual JAR that will be used in this module's classpath, and a dependency - the 'hello' module.

Same module.xml for the 'hello' module:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.5" name="hello">
    <resources>
        <resource-root path="hello.jar"/>
    </resources>
</module>


Voila! Now we can execute our brand new modular "Hello World" app:

java -jar jboss-modules-1.5.1.Final.jar -mp mods app

Hello! 

The format for the command is as follows. First, java -jar jboss-modules.jar is used to bootstrap the environment; -mp mods, and the 'app' parameter is the name of the application module that should be executed.

This example isn't really practical, but at least it gives a hint on how to get started with JBoss Modules. Hopefully, one day, the documentation for this awesome project will be complete and there will be a few more tutorials for different the use cases.

JBoss

Published at DZone with permission of Anton Arhipov, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Evolution of Recommendation Systems: From Legacy Rules Engines to Machine Learning
  • Okta + SAML + JBoss EAP 6.4.x + Picketlink

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!