As any license enforcement solution can be cracked with a bit of effort, I suggest you don't try to implement copy-protection at all. License management is just inconvenient for your users.
If you are determined to implement copy-protection, you can use an open-source library.
Additionally, you should obfuscate your byte code to make it slightly more difficult to reverse-engineer your application.