How to protect a Jar file from being decompiled? [duplicate]
Asked Answered
U

5

11

I'm developing an application using java but I'm not going to release the code. The problem is, I tested one of these jar de-compilers and it was able to get the code from my jar file almost perfectly! My question is how can I distribute my jar file without my code being extracted from it?

Underbrush answered 9/3, 2012 at 11:40 Comment(1)
I found out that suggested duplicate actually does answer my question. Thanks for the directions.Underbrush
N
9

As Java preserves most of the "metadata" during compilation (which allows dynamic loading and reflection), it is a straight forward to decompile (not only disassemble) the compiled class files. That's why the recovered code is very similar to the original.

While not perfect, your probably only option is to use an obfuscator, such as ProGuard.

Navarra answered 9/3, 2012 at 11:42 Comment(0)
F
6

You can't. At the minimum, the JVM is going to need to get the code out in order to run it. And if the JVM can get the code out, anyone can.

The best you can do is obfuscate the code, but I would recommend against it because it will make tracking down production bugs very difficult because the stack traces will be hard to follow.

Francesco answered 9/3, 2012 at 11:42 Comment(1)
I understand the (good) obfuscation tools provide a table you can use to translate the stack output of the runnable to the original classes and code lines. But they are generally more effective at compressing code, than protecting it.Retirement
B
2

There is no possibility to protect the code from disassembling. You can use obfuscation tool like 'proguard'. Even after decompilation it will be almost impossible to understand the code.

Batchelor answered 9/3, 2012 at 11:43 Comment(0)
V
1

Obfuscate your code using some obfuscator in the market. Obfuscators change the names of your class and its methods to some weird looking names so that it becomes hard for people to make sense of the code. Mind it, people would still be able to decompile your code but only thing is it would be hard for them to understand it due to the jumbled names.

Downside of this is, it would be hard for you to debug and support the obfuscated code in case your customer faces some issues as the stack traces in the exceptions would have the jumbled up class and method names.

Vachon answered 9/3, 2012 at 11:47 Comment(0)
E
1

it's never impossible to reverse-engineer in java but i think that Proguard is the best. It is also possible to integrate it with your IDE (for example NetBeans). and ygard for ant

Ewold answered 9/3, 2012 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.