Software Development

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.

[wp_ad_camp_1]

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.

[wp_ad_camp_2]

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.

[wp_ad_camp_3]

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

[wp_ad_camp_4]

Proceed to lib\ext directory under jre.

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

Test your App

[wp_ad_camp_5]

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:

 

 

 

 

 

 

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like