Solved

How to overwrite a class in a jar file

Posted on 2013-12-12
3
1,060 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 36

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

615 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