Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 338
Pouya Avatar asked Mar 09 '12 11:03

Pouya


2 Answers

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.

like image 160
MByD Avatar answered Sep 30 '22 14:09

MByD


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.

like image 23
dty Avatar answered Sep 30 '22 13:09

dty