Solved

How to overwrite a class in a jar file

Posted on 2013-12-12
3
799 Views
Last Modified: 2013-12-17
I have a jar file built by someone else. But for one of the java class, I want to use my own version. When running the java program, how to let it reference the class of my own version?
0
Comment
Question by:gs_kanata
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 39714553
One simple way would be to simply unpack it and repack it with your own. You should be OK - unless the archive has been signed
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
ID: 39715446
Another possibility (althouh not generally advisable) is that if you have full control over the classpath while running your application, you can set the classpath to include the directory/jar file that contains your version of the class BEFORE it includes your 3rd party jar file.

Again, though, I say that this isn't advisible in the general sense. I would only use this as a last resort and only where it isn't critical, ie. I would only do this for an app that I run myself, where I have control over it and I can tell if the "replacement" class didn't get picked up.
0
 

Author Closing Comment

by:gs_kanata
ID: 39724976
I tried both ways, not that simple.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now