Johnydep
Johnydep

Reputation: 6277

How to export my Java Project as external Jar without including source code

so i have made some java files which provide some specific API functionality. I want to export them as a Jar file which can be imported in class-path so that its functionality can be used by those who use this file.

Now when i export this via Eclipse, it includes all source files in the jar, and anybody would be able to copy my code. Is there any way i can hide the source code so that API functionality can be used without seeing the actual source code of these java files?

Please suggest if it is possible or not.

Thank you,

Upvotes: 2

Views: 8317

Answers (3)

Harry Joy
Harry Joy

Reputation: 59650

When exporting jar file from eclipse untick the check box for Export Java source files and resources. in second step of wizard.

enter image description here

Upvotes: 2

duffymo
duffymo

Reputation: 308733

Don't put the source files in the JAR. It should only contain .class files - compiled byte code.

You realize, of course, that anyone can decompile your .class files and get .java back if they really want to. You'd have to take extraordinary steps like encrypting your .class files and writing a special class loader to decrypt them.

I don't think it's possible to prevent someone from copying your code if they're truly determined. The good news for you? Nobody wants to take your code.

Relax and release that JAR without .java in it. You'll be fine.

Upvotes: 6

Valchev
Valchev

Reputation: 1530

Please, make sure that in eclipse' "JAR Export" dialog the option "Export java Source files and resources" is unchecked.

Just to mention that probably is better to use some build system like maven or ant.

Upvotes: 1

Related Questions