-1

I think this is a super easy question, but im new to this and not sure what to do. So I have added an external jar file into one of my projects, and was able to decompile the classes using JAD to see some of the class files, the thing is I want to add a new class to one of the directories in same JAR file, compile it and update the jar file. I was googling and I came up with things like an 'ANT build file' but not sure how that would work?

Thanks!

Thatdude1
  • 905
  • 5
  • 18
  • 31
  • Would this help? http://stackoverflow.com/questions/869034/using-ant-to-generate-a-jar-in-a-very-large-project?rq=1 – Josh Nov 01 '13 at 14:32
  • So if you have decompiled and added the source to your project you can export it as jar with you new class by File > Export > Java > Jar option – Abdullah Shaikh Nov 01 '13 at 14:33

2 Answers2

1

First of all i would check out if the developper of that JAR has provided the source to the classes. This reduces the possibility of JAD not beeing able to fully decompile all the class information.

However once you have all the .java files (including your changed or added class) you can let eclipse build the jar file as follows:

1.) Compile the .java files (Project -> clean..)

2.) File -> Export -> Java -> Jar file (click next)

3.) Select anything that belongs to the jar, input a name and click finish (Note the checkbox that says to export generated class files and resources).

Regarding Ant/ Maven and stuff: Those are just tools that help you. The same result you can archive by opening a console and use javac.exe to compile you can use ant or maven to compile your classes. Its just a matter of configuration.

I recomend you skip Ant right here and directly do the Maven in 5 Minutes tutorial :)

JBA
  • 2,769
  • 5
  • 24
  • 40
  • 'Compile the .java files (Project -> clean..)', what exactly would i compile the new class file i created ? – Thatdude1 Nov 01 '13 at 17:14
  • Differ between .java files and .class files. You used JAD to decompile .class files back .java files. Then you want to add an own class which is .java as well. But to get back the "original" usable jar you have to compile all the .java files to .class files before packing them into an .jar file. Try the export right away, i bet eclipse compiles them then as well (Project/clean is as well just a trigger to make it build your workspace and thatfore compile all your .java files) – JBA Nov 01 '13 at 17:23
0

Your approach works. But you can have two classes with same name and package. This will remove the necessarily of updating the jar file.

You must set the loading order to make sure that your new modified version will be used instead of the one which is in the jar file. Possible to use two java classes with same name and same package?

Before any tweak and class loader, test this approach, may be the default class loader behavior will do what you want.

Community
  • 1
  • 1
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173