Jar File - Prevent Access to Source Code

前端 未结 10 1151
别那么骄傲
别那么骄傲 2021-01-19 16:40

I want to hand over a small Java app as a runnable jar but I do not want anybody to have access to my source code. Am I right in presuming that there is no source code (.jav

相关标签:
10条回答
  • 2021-01-19 17:11

    You are right, there is no source code in the jar (unless you configure your build system to specifically put it in there). But you are always at the risk you code gets decompiled from the bytecode. An obfuscater might help here.

    0 讨论(0)
  • 2021-01-19 17:12

    Assuming you don't put the java files in the jar file, they're not going to magically appear :) You can include anything you like in the jar file of course. You can list the contents to check:

    jar tvf foo.jar
    

    Note that Java can be decompiled pretty easily though - so while any recipients wouldn't have access to your actual source code with comments etc, they could see your logic pretty clearly. You may want to use an obfuscator to help protect your IP. Personally I try to avoid obfuscators - given how hard most of us find to maintain code when we do have the real source with commments and tests, imagine how hard it is when you don't have those things :) It's your call though. Just make sure you test obfuscated code thoroughly - there can be subtle issues, particularly if you use reflection.

    0 讨论(0)
  • 2021-01-19 17:12

    If a computer can run it, a human can reverse engineer it, and it is not particularly hard for Java.

    So technical protection simply won't work. You need legal protection in form of a binding contract or similar. You may even put your works under the GPL except for those paying you, which is sufficient for most businesses to avoid stealing your work.

    What situation exactly do you want to avoid?

    0 讨论(0)
  • 2021-01-19 17:13

    Yes. Usually, jars contain only byte-compiled .class files. That said, they can contain source code as well—it depends on what you (or your tools, respectively) put into them.

    Note, however, that decompilation works pretty well on .class files, so don't make anything security-related rely on code obfuscation techniques such as this one.

    0 讨论(0)
  • 2021-01-19 17:13

    It will depend on the way you generated that .jar, Eclipse does have an option to include .java files on the .jar but it is disabled by default and you have to activate it if wanted.

    0 讨论(0)
  • 2021-01-19 17:14

    You are are correct, however the .class files can easily be disassembled to java code, and its pretty accurate in most cases.

    If you really need it to be properly secure then you'll need to obfuscate.

    0 讨论(0)
提交回复
热议问题