0

Sorry if the title doesn't say what I'm trying to do very accurately but I wasn't really sure how to describe it in one sentence. Basically I have a jar file with a java file inside it, and I want to edit the java file. I used 7zip to do so and it worked, letting me edit the code in the java file. I saved it and my new code shows up when I open the java file in netbeans. However, the new code isn't actually in effect, and my program is still using the old code. I don't know if this matters, but the java file is named Templates.java, located in a package called net.sf.dynamicreports.examples in a jar named dynamicreports-examples-5.0.0-sources.jar.

Thanks in advance for any help anyone can offer.

Edit: tried importing the jar into a new project and editing from there before putting it back into the original project, but had no luck (check comment chain for further details). Still have no idea how to fix this and would greatly appreciate any help

1 Answer 1

1

Your jar contains .class files and .java files. When you create the jar, the .java files are compiled and .class files are created from them. You should have a Templates.class file that corresponds to Templates.java. When you edited Templates.java, Templates.class was never recompiled. This class file is the one your program uses. The appropriate way to change a jar file is unfortunately to regenerate the entire jar.

So, what you should do is open the code you used to create the jar in the first place, make your java changes there, and create a new jar. You will need to do this even with the smallest changes.

I didn't make the jar myself unfortunately, I got it from somewhere else so I don't have the code used to make it, just the jar itself. What should I do?

Edit: I saw your comment that you did not make the jar in the first place. This isn't too big a problem since you do have the java source code. What you need to do is copy all the .java files in the jar and make a new jar with them. Or, simply use Eclipse or whatever your favorite java editor is to compile your Templates class, and copy the new Templates.class file it creates into the appropriate place in the old jar, overwriting the old one.

Where would I find the Templates.class file?

Edit 2: You find the class file in the bin folder of your project if you are using Eclipse. See this question: Find the .class file compiled by Eclipse or if you are using a different editor/compiler, search google for where it stores its .class files.

20
  • I didn't make the jar myself unfortunately, I got it from somewhere else so I don't have the code used to make it, just the jar itself. What should I do?
    – Evan
    Commented Jun 23, 2017 at 16:22
  • Where would I find the Templates.class file?
    – Evan
    Commented Jun 23, 2017 at 17:06
  • I found the class folder but it only has .class files for the java file itself rather than any .class files for my jars. Am I looking in the wrong place or did I do something wrong? I'm using netbeans by the way
    – Evan
    Commented Jun 23, 2017 at 17:42
  • Where did you edit your Templates.java file? If you did it in anything other than notepad or some kind of text editor, it should have made you a .class file when it compiled it. I don't know netbeans and I'm sorry I can't be more helpful other than to tell you to just look for it.
    – MMAdams
    Commented Jun 23, 2017 at 18:31
  • When I used 7zip I was able to go into the jar file and found a notepad of the Templates.java file. Is it a problem that it was done in notepad?
    – Evan
    Commented Jun 23, 2017 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.