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

  • SEARCH
  • Home
  • 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 6655145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:28:47+00:00 2026-05-26T01:28:47+00:00

I have 3 Java projects A, B and C. B is like an add-on

  • 0

I have 3 Java projects A, B and C.
B is like an add-on to A. A and B both depend on project C for some classes.

Now in project A when I use a URLClassLoader as follows:

URLClassLoader ucl = new URLClassLoader(urls); //urls are paths to some classes in B

Now when using these ucl, when I call some methods in B, it gives me No Class Definition found exception. This is for a class which is C.

Now when I use the ClassLoader as follows:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URLClassLoader ucl = new URLClassLoader(urls, classLoader);

This works fine when I call the methods in B.
My Question:

1) When I do it the first way, which ClassLoader is being used? I read the JavaDocs, but couldn’t find anything that I could explain myself to.
2) Is there a way to get a ClassLoader which will be specific to project B, that I can use somehow, so that I won’t hit any dependency issues?

Thanks for any help.

  • 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-26T01:28:48+00:00Added an answer on May 26, 2026 at 1:28 am

    The default class loader is the system class loader (loads the classes on the classpath).

    If you loaded classes in B with a specific class loader, use that instance. Otherwise someTypeInB.getClass().getClassLoader() will do as a hack.

    (Note: Using URLClassLoader.newInstance is generally preferable to new URLClassLoader, as it adds in security measures necessary (though not really sufficient) for use with untrusted code. Also using the thread context class loader is generally a bad idea – you introduce a dependency upon the local piece of code to however threads are setup and used [which probably doesn’t have any coherent policy applied to it anyway].)

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

Sidebar

Related Questions

I have multiple Java projects in Eclipse. I would like to reuse some classes
I have some experience writing web applications in Java for class projects. My first
I've just started using Java's enums in my own projects (I have to use
I have a simple java maven project. One of my classes when executing needs
We have a library of Java code that we intend to use across projects.
We have a project structure like following: sharedlib (lib-project, containing classes, that are useful
I have a workspace with a bunch of java projects. If I go to
In our infrastructure, we have lots of little Java projects built by Maven2. Each
I have been working in Java/J2ee projects, in which I follow the Maven structure.
I have a large Java app that is split up into multiple projects. Each

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.