Java. Using the jar.


You need to use a function that is located in a certain jar. There are no source codes. But at the same time, I do not want to increase my program by a couple of MB for the sake of one function. Is it possible to solve this problem somehow?

Author: azat, 2013-11-29

8 answers

If you really need this code, then there is only one way out: decompile it .jar file, and then just copy-paste the necessary code to yourself. Anyway, you can just open the jar via the JD-GUI (~0.5 MB, no installation), without even wasting time decompiling.

 3
Author: Helisia, 2013-11-29 20:27:35

You can decompile it!


Get the necessary methods for your actions and implement them yourself in your program

With the help of the decompiler, you can not only take a certain file from .Jar, but also any of its packages.

A small list of pre-compilers:

Java Decompiler

Probably the most popular Java decompiler. It itself provides a console interface, has not been supported or updated for a long time, but still many graphical tools that work with this decompiler still make it useful when you need to decompile small Java classes.

Mocha

It is one of the first Java decompilers released. Like JavaDecompiler, Mosh provides a console interface, the last release was already in 1996.

DJ Java Decompiler

For a long time, it was used only as a graphical Java Decompiler shell for faster and more convenient selection of command-line arguments for calling JAD. However, the current version has support for annotations.

Fernflower

Probably one of the best decompilers of Java applications at the moment. The latest version includes support for parametric types, annotations, statements, enumerated types, and also really competently decompiles bytecode obtained due to known compiler bugs.

Java Decompiler project

JD-Core

A highly functional library for decompiling Java bytecode, developed as part of the "Java Decompiler project". It is written entirely in C++ (extremely fast), does not require special installation, correctly performs its immediate task, although this decompiler is distributed as part of the JD-GUI application, which does not allow its development in a third-party project.

To this project enter:

  • JD-GUI

  • JD-Eclipse

  • JD-IntelliJ

Personally, I really like the built-in decompiler in the Intellij Idea IDE, it parses the code very well. It is so cool that you can go to the source code of java itself and see how it works and what works. Well, a very cool product...

The only thing I want to say is: "Remember about copyright!". Before decompiling, make sure that you will not break the law. (for yourself in the quiet you can)

 2
Author: Виталий Вихляев, 2015-07-25 11:56:50

AFAIK jar is a zip archive of .class files. You can try to pull out only the .class file you need and connect it to your project.

 1
Author: Олег Нечитайло, 2013-11-29 20:45:14

Only one way is to write the same function, if of course it is feasible.

 0
Author: Mage, 2013-11-29 20:14:35

I suggest using the analytical decompiler Fern flower At the same time, this decompiler helped me a lot to get the code of a commercial billig. The quality of the work of the decompiler is not acceptable, I managed to pull a lot with the moposchyu of this product.

 0
Author: huffman, 2013-11-30 04:10:03

And what if you open this jar and view its .class files via IDEA - this is certainly not the source code, but if you really want to, you can copy-paste the desired method.

 0
Author: Kirill Stoianov, 2017-07-12 14:55:39

Here is another service for online decompilation of jar and class files to the source Java code: Decompile Android Apk Fast and convenient and no need to configure anything.

 -1
Author: Max, 2017-07-12 13:04:19

Maybe it's easier for you to connect only 1 function to the source?

import lala.blahblah.some_func;

If you do not use decompilation, then this is the best way. Only 1 function will be added to your program code, but there will be dependencies

 -2
Author: voipp, 2013-11-30 08:08:49