Peter
Peter

Reputation: 4141

Build a JAR file that can only be executed?

My project isn't complete, but I'd like to distribute some demo versions.

Is there a way to make a executable JAR file that won't give users access to its classes (e.g. when imported into Eclipse)?

Upvotes: 1

Views: 99

Answers (3)

Ayushman
Ayushman

Reputation: 272

Did you try Export>Java>Runnable JAR file option in Eclipse?

Upvotes: 0

Tim
Tim

Reputation: 6509

No, a jar file is a zip file and there's no way to stop your users from looking inside it - because the JVM needs to look inside it to run it.

You can however:

  • Try converting it into a native executable (there are a few tools to do that)
  • Run an obfuscator over it (there's even more tools for that)

My experience with obfuscators are that they don't do a good enough job to acutally stop someone who's really keen. I've tried running decompilers over a variety of obfuscated classes and they're still easy enough to understand.

If you're interested in the native exe path, then this article might help.

Generally speaking, I don't think it's worth pursuing. If what you're distributing it valuable enough to the people you're giving it to, then they'll find a way to dig inside if they want to. Or if they're trustworthy then they won't. But technological solutions probably won't change that.

Upvotes: 2

Dave Newton
Dave Newton

Reputation: 160181

Your only hopes lie through obfuscation or encryption. Neither is all that awesome in terms of protection against a determined poker-arounder. You sure it's worth it?

ProGuard is a free obfuscator (among other things). Encryptors use custom classloaders to decrypt encrypted byte code on loading.

Upvotes: 2

Related Questions