Solved

How to overwrite a class in a jar file

Posted on 2013-12-12
3
933 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I remove an object from a 3 40
jmss example java 2 24
Html Table Looping (part 2) 5 28
jsp error 6 27
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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 …

820 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