Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:21:26+00:00 2026-05-18T23:21:26+00:00

In which case one would use a URLClassLoader to load a class from a

  • 0

In which case one would use a URLClassLoader to load a class from a specific jar in a specified path?
E.g.

URL url = new URL("file:///path/to/customClasses.jar");
URLClassLoader pluginLoader = new URLClassLoader(new URL[] { url });
Class<?> cl = pluginLoader.loadClass("apackage.MyCustomClass");

If I wanted to use classes from customClasses.jar, I always thought that placing this jar in a path accesible from CLASSPATH is enough.
Then in my code just use apackage.MyCustomClass.
I think I have something missunderstood or missing here, so could someone please explain and give an example of when the above snippet of loading class this way is useful?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:21:27+00:00Added an answer on May 18, 2026 at 11:21 pm

    I would say that depending on the type of programming you are doing, the use of the URLClassLoader should be a very rare occurrence.

    Typically you will use the class loader for loading in classes at runtime that you couldn’t anticipate in advance.

    A good example is if you build a tool that can be extended with plugins, and the plugins are loaded at runtime. For example, Eclipse.

    If you have the jar available at compile time and are on a command line, add the needed jar file to your compile statement. For example,

    javac -cp /path/to/lib/customClasses.jar MyClassThatReferencesCustomClasses
    

    If you’re using Eclipse, add the jar to your project, and right click on it and select add to build path.

    Regards,

    Will

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to System.Action<T> and Lambda expression. Here is one case I would
I can imagine one case, in which the input parameter could be NULL so
In which case should you use primitive types( int ) or reference types (
I use camel case which has the first letter of all variable names, functions,
In C++, I can't think of a case in which I would like to
Which checksum algorithm can you recommend in the following use case? I want to
What are the scenarios when one would use a Monostate pattern instead of singleton
A lot of frameworks use URL conventions like /controller/action/{id} which is great, but if
Here is my code, which works perfectly except for one case: when I have
The code below works unless p.School.SchoolName turns out to be null, in which case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.