0

Java – Run application without classpath using Extension Mechanism

In Java, it is possible to “extend” your currently installed JRE in a way that your classes are loaded automatically thereby removing the need to specify them in the classpath. This is done using Java’s Extension Mechanism.

Below is an image showing the general idea of the Extension Mechanism.

extae22212e

Overview of Extension Mechanism

Extensions are Jar files

Creating extensions is easy. All you need to do is bundle your classes into a JAR file.

Our Classes

We begin with two files – TurretaExtMainClass.java and TurretaExtSomeOtherClass.java. Nothing fancy. Just a main class that uses another class.

Create a Jar file

There are several ways to create jar files. Here, we’ll do the simplest and primitive way.

Note: this assumes that /path-somewhere/classes contains the com directory.

I am using Java 8 for this. You can check if you are using the correct platform.

This outputs

So, finally out extension is turreta-ext.jar which we will drop into the ext directory in Java home directory.

Drop it in the ext directory

Okay, make sure you are in the correct Java home directory.

13-11-2016-1-58-38-pm

Proceed to lib\ext directory under jre.

13-11-2016-2-24-40-pm

Test your App

13-11-2016-2-28-05-pm

You’ll notice my command prompt is “ms-dos:”. I changed it to keep things short.

Just type:

 

 

 

 

 

 

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert