I have a .jar file; in this .jar file I have many .class files but no .java files for these class files. Is it possible to add functionality to the program? If so how?

Recommended Answers

All 7 Replies

I have a .jar file; in this .jar file I have many .class files but no .java files for these class files. Is it possible to add functionality to the program? If so how?

since you don't have the java files, I take it you didn't write the original code.

if you did write the code, you could try to decompile it, and 'add' code, but if it isn't yours, I would just write some extra classes that use the methods you want to 'improve' and that fix your problem. or, you can write some new classes that extend the older ones, and overwrite the methods you want to see executed otherwise

Agree with stultuske. You need to create something like a "wrapper" class. Lets say for example the jar file will load an employee, but you want to add a check if the employee is still active.

Create a method in your wrapper class to call the jar and load the employee, then add in your check for active into your wrapper class as well.

The problem is, I am not the author of the original and as such have not clue as to what methods the classes have and in which class.

>The problem is, I am not the author of the original and as such have not clue as to what
> methods the classes have and in which class.

Then how do you propose on adding additional functionality as mentioned in your first post?

commented: That's exactly what I was wondering. +13

The question was is it possible? I never once implied I intended to do so. Is it possible to add functionality, if so under waht circumstance and how.

From what I can deduce from the replies, there is the suggestion that yes, if I know the classes and the methods and no if you do not know anything about them. Am I right in drawing to this conclusion?

Many thanks

Yes, it's possible to "add further functionality" by composing new classes of your own that use those classes internally to extend or alter the functionality (assuming there are not licensing issues). Of course, you do need to understand the API of the other classes if you expect to do much with them, which was s.o.s's point.

If you stop to think on it a moment, you do this any time you write a program with the JDK. You utilize the existing classes in the API to build new ones of your own that offer some intended functionality.

commented: Very good point =) +4

Your comments are very much appreciated.

I thank you all.

commented: You are a very grateful person =) +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.