• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make sure that a particular class gets loaded first in the memory.  RSS feed

 
trupti nigam
Ranch Hand
Posts: 640
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using a **.jar file in my application. The class "A" from the jar file may not work for my app so I need to add that class in my project and customize it. But I need to make sure that this class gets loaded first and not the Same "A" class from the jar. How to make sure that the class "A" from my project gets loaded first?

thanks
Trupti
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that you are playing with fire and need to find a different approach to solving your problem.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear has already said it's best to not even try. The safest thing to do is put your version of the class in your package space and make sure all your classes that use it import the class from your package.

If there are other reasons that mean you really have to do this there are a couple of possible approaches I can think of (there are probably others) ie:
1. The simplest and most likely to fail is to arrange the classpath setting so your version of the class is likely to be found first - I would not recommend this approach at all.
2. Write your own ClassLoader that knows which jar to use when the given class has to be loaded.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!