How I Built and Published My First Java Package - Numsy

Rohit PatwaRohit Patwa
3 min read

Table of Contents


Recently, I built a small nut useful java utility package called Numsy, and published it to Github Packages. Here’s a quick walkthrough of how I did it, step-by-step . Hope it helps you are planning to publish your package!


What is Numsy ?

Numsy is a lightweight Java utility library for basic number manipulation, formatting, and checks.

Currently it supports :

  • Check if Number is Even or Odd

  • Check if Number is Prime or Not

  • Find Prime Number within a range.

  • Number formatting- Add Commas

  • Find GCD

  • Find LCM

it’s nothing fancy — Just something useful that java doesn’t offer directly in a clean, reusable way.


Step-by-Step: Building the Package

1. Generate a maven Project

I used the maven archetype to create the project quickly:

mvn archetype:generate \
  -DgroupId=com.therohitpatwa \
  -DartifactId=Numsy \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false

This will create a folder structure like this.

(It will also create test folder, but we won't bother with that for now. also ignore the .gitignore, give it teste of its own medicine 😁)

2.Implement the Utility class

In src/main/java/com/therohitpatwa/Numsy Numsy.java, I added some static method:

public static Boolean isEven(int n) { ... }
public static Boolean isOdd(int n) { ... }
public static List<Integer> primeInRange(int start,int end) { ... }
So on...


Publishing to GitHub Packages

3.Set Up pom.xml

I updated my pom.xml to include the Github packages repository under distributionManagement.

<distributionManagement>
  <repository>
    <id>github</id>
    <name>GitHub Packages</name>
    <url>https://maven.pkg.github.com/Github_Username/textee</url>
  </repository>
</distributionManagement>

4.Authenticate with GitHub

In your Maven setting.xml (In ~/.m2/setting.xml file), added my GitHub credentials like this:

<servers>
  <server>
    <id>github</id>
    <username>YOUR_GITHUB_USERNAME</username>
    <password>YOUR_PERSONAL_ACCESS_TOKEN</password>
  </server>
</servers>

To create YOUR_PERSONAL_ACCESS_TOKEN:

  1. go to github.com/settings/tokens

  2. Create a Classic Token with these scope enables: write:packages read:packages

  3. Create and Paste it in the setting.xml

5.Deploy the Package

Run this command to publish:

mvn clean deploy

You'll see the packages listed under Packages in your GItHub repo if all goes well!


Using the Numsy Package in Other Projects

In other project’s pom.xml, include the repository and dependency:

<dependencies>
  <dependency>
    <groupId>com.therohitpatwa</groupId>
    <artifactId>numsy</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>
</dependencies>

Now Import com.therohitpatwa.Numsy

and you can use methods provided in Numsy class of numsy

Syntax -Numsy.methodName();

Final Thoughts

I will add more method in Numsy soon. if you would like to use it or contribute, check it out here —
👉 Numsy

10
Subscribe to my newsletter

Read articles from Rohit Patwa directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Patwa
Rohit Patwa