I am building some java jar building through Maven but I need to put certain time stamp that should make that JAR expired with certain date that is fixed/provided in the JAR.
Thanks Kumar Shorav
I am building some java jar building through Maven but I need to put certain time stamp that should make that JAR expired with certain date that is fixed/provided in the JAR.
Thanks Kumar Shorav
There are several ways:
Hardcoded
Somewhere in your code, you'll have
if (currentDate > hardcodedDate) System.exit(0);
runYourCode();
This is pointless. For everybody who knows about decompilation, it's an easy trick to change that to:
// if (currentDate > hardcodedDate) System.exit(0);
runYourCode();
Properties
In a properties file, you keep the number of days it should work. On startup of your application, you check whether or not a certain file exists. If it doesn't -> create it, and put nothing in it but your current system date. On every next startup:
Date check = readDateFromFile();
if ( currentDate > check + numberOfDays ) System.exit(0);
Again, easily faked. All you need to do is delete the created file, turn back the system date, ...
Distributed
This is what I would at least consider. Distributing all your code means it can be copied as much as the user wants. Tricky business, since if they know your code, they can alter it.
Create a client that contacts the service that handles your business logic. Make sure each client has a 'key', whether it's hardcoded or in a properties file, this is irrelevant. In your db, keep a list of all the keys, both trial and real ones. For the trial keys, at the moment of first use, you add a value in the DB -> current system date + numberOfDaysAllowed. On every other use, check that value against the system date (not the system date of the client, but of your server). Date reached? delete the trial key from the db, or set a flag 'Expired' to true. Then, check if it the serial is in the DB, if it is, whether the flag is expired. If the serial is not in the DB, or the flag is expired, terminate program. The client might try to tamper with the key, but if he does, the key won't be recognized in your system (map it to a user, if you want to be more sure), and 'll fail anyway.
Buy a tool
Let's face it, people who create software to do this, also need to earn their income
Search a free tool
In the thread I linked to, there's a link to this page: trial maker, which seems to be free.
Build a tool
If you don't want to buy a tool, and you aren't satisfied with any existing free tool, feel free to build your own.