Batakj
Batakj

Reputation: 12743

How tomcat loads a jar file?

Putting a jar file under Tomcat/lib folder. And tomcat loads the jar file.

My Question is:

How does tomcat load a jar file? e.g. Unpack, then index it, look for the class and load it using reflection.. Which i can guess..

Is there any library in java from which i can make a similar application?

My Objective:

I have an java interface which will supposed to extend application capabilities. There is a default implementation. But, in the future, it will be changed and can have multiple copies/version.
The idea is to provide implementation and pack it into a jar file and drop it into a folder. The container will look for the implementation and list down the implementation.

An End-User who use the application can choose default or any version...

Example: Default theme..

Now, i have an interface

public interface Theme
{
  public void setName();
  public void setColor();
  public void setBGColor(); 
  public void getName();
  public void getColor();
  public void getBGColor(); 
}

Admin created two theme i.e. BlueWITHGreenBGTheme and GreenWITHBlackBGTheme. Compiled it and packed it and drop into the folder..

End-User will now see three different theme : Default Theme, BlueWITHGreenBGTheme and GreenWITHBlackBGTheme. He/She Choose any theme and his/her application color and background color change.

Above is just an example, not the real scenario.

Upvotes: 3

Views: 809

Answers (1)

aalku
aalku

Reputation: 2878

Tomcat uses a custom ClassLoader.

You can make your own too but URLClassLoader satisfy the requisites of most developers.

Don't think URL are about internet, they may point to local jar files too.

Upvotes: 1

Related Questions