1.生成truelicense的maven项目
mvn archetype:generate -B -DarchetypeArtifactId=truelicense-maven-archetype -DarchetypeGroupId=net.java.truelicense -DarchetypeVersion=2.4.1 -DartifactId=blps_license -DcompanyName="qptx" -DdefaultPassword=ttkk1234 -DgroupId=com.toptoken -DlicensingSubject="blps" -Dversion=1.0-SNAPSHOT
2.maven安装并测试maven项目
mvn install -Pintegration-test
3.生成license认证文件
java -jar blps_license-keygen/target/blps_license-keygen-1.0-SNAPSHOT-standalone.jar create blps.lic -verbose true -input e:\truelicense\lic.txt
lic.txt文件内容如下
{"extra":{"yljgCode":
45535,"yljgName":"
石家庄市中医院"},"consumerAmount":1,"consumerType":"User","holder":"CN=toptoken","issuer":"CN=toptoken Inc.","subject":"blps","notBefore":"
2015-04-25","notAfter":"
2015-05-25"}
4.命令行测试认证文件
#安装证书
java -jar blps_license-keymgr/target/blps_license-keymgr-1.0-SNAPSHOT-guarded.jar install e:\truelicense\blps_license\blps.lic
#查看证书
java -jar blps_license-keymgr/target/blps_license-keymgr-1.0-SNAPSHOT-guarded.jar view
#图形界面操作 安装 卸载 查看证书
java -jar blps_license-keymgr/target/blps_license-keymgr-1.0-SNAPSHOT-guarded.jar wizard
#命令行证书验证
java -jar blps_license-keymgr/target/blps_license-keymgr-1.0-SNAPSHOT-guarded.jar verify
#证书卸载
java -jar blps_license-keymgr/target/blps_license-keymgr-1.0-SNAPSHOT-guarded.jar uninstall
5.代码验证证书及使用
String classPath = AppInstaller.class.getClassLoader().getResource("").getPath();
LicenseConsumerManager manager = LicenseManager.get();
LicenseConsumerContext context = manager.context();
Source source = context.fileStore(new File(classPath+File.separator+"blps.lic"));
try {
manager.install(source);
License view = manager.view();
String extra = view.getExtra().toString();
System.out.println("========================");
System.out.println(extra);
System.out.println(view.getNotAfter());
manager.verify();
System.out.println("=============SUCCESS===========");
} catch (LicenseManagementException e) {
System.out.println("=============FAILTRUE===========");
e.printStackTrace();
}