Setting Licence Path through API
Added by ozkan ozcan almost 7 years ago
Hi All,
I need to set the license path programmatically. can you please tell me how to do that?
I have tried this piece of code:
EnterpriseConfiguration conf = new EnterpriseConfiguration();
conf.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, "E:/MySpace/lib/SaxonEE9-8-0-4J/saxon-license.lic");
I got the below exception Exception in thread "main" net.sf.saxon.trans.LicenseException:
Thanks, Özkan
Replies (9)
Please register to reply
RE: Setting Licence Path through API
-
Added by Michael Kay almost 7 years ago
This is working for me. If I supply a filename that contains a valid license, all is working OK. If I supply a filename that does not exist, I get:
@net.sf.saxon.trans.LicenseException: Failed to read license file /Users/mike/inactive-license/saxon-license.lic@
If I supply a filename that is not a license file, I get
@net.sf.saxon.trans.LicenseException: Invalid encoding for signature@
Are you sure there is no message associated with the exception?
One possibility is problems with the license file encoding. There is a history of problems when license files contain non-ASCII characters, partly caused by the fact that we transmit them by email, and partly a legacy issue because we have to be able to read license files issued years ago when these were in Windows-1252 encoding.
RE: Setting Licence Path through API
-
Added by ozkan ozcan almost 7 years ago
Hi Michael,
Thanks for your reply.
I am evaluating saxon ee for xsd1.1 validation. It is very important that I am able to supply the the license key.
File license = new File("e:/MySpace/lib/SaxonEE9-8-0-4J/saxon-license.lic");
File saxonConfig = new File("saxon.xml");
String licensePath = "E:/MySpace/lib/SaxonEE9-8-0-4J/saxon-license.lic";
EnterpriseConfiguration conf = (EnterpriseConfiguration) EnterpriseConfiguration.readConfiguration(new StreamSource(saxonConfig));
File xsd = new File("e:/MySpace/ps-commons/src/test/resources/com/sdl/ps/commons/text/xml/validation/SDB_Schema_Length.xsd");
File xml = new File("e:/MySpace/ps-commons/src/test/resources/com/sdl/ps/commons/text/xml/validation/SDB_4_20170124_1214_de_zh.xml");
conf.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, licensePath);
com.saxonica.ee.jaxp.SchemaFactoryImpl factory = new com.saxonica.ee.jaxp.SchemaFactoryImpl();
it throws the below exception when I try to create a schema factory.
Exception in thread "main" net.sf.saxon.trans.LicenseException: License file saxon-license.lic not found. Tried in file:/E:/MySpace/lib/saxon-license.lic, and classpath. A license is needed to use schema processing
at com.saxonica.config.EnterpriseConfiguration.checkLicensedFeature(EnterpriseConfiguration.java:311)
at com.saxonica.ee.jaxp.SchemaFactoryImpl.(SchemaFactoryImpl.java:59)
at webdriver.test.SaxonTest.main(SaxonTest.java:34)
RE: Setting Licence Path through API
-
Added by Michael Kay almost 7 years ago
If you're loading the Configuration from a configuration file rather than creating it programmatically, then you need to specify the license file location in the configuration file itself:
Supplying the license file after reading the configuration file is too late, because Saxon needs to check the license while processing the configuration file.
RE: Setting Licence Path through API
-
Added by Michael Kay almost 7 years ago
I've been doing some tests and what I wrote above is only partially true. In some cases it is possible to set the LICENSE_FILE_LOCATION property on a configuration that has been built from a configuration file. But it depends what is in the configuration file: if the configuration file sets any properties that depend on a license being available, you'll get a failure because the license file is not yet known. So naming it within the configuration file itself is safer.
RE: Setting Licence Path through API
-
Added by ozkan ozcan almost 7 years ago
In fact I have also specified the license file location in the config file. Like this
I have now removed the part loading configuration from config file.The code is like this now :
String licensePath = "E:/MySpace/lib/SaxonEE9-8-0-4J/saxon-license.lic";
File licenseFile = new File(licensePath);
System.out.println(licenseFile.exists());
EnterpriseConfiguration conf = new EnterpriseConfiguration();
conf.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, licensePath);
com.saxonica.ee.jaxp.SchemaFactoryImpl factory = new com.saxonica.ee.jaxp.SchemaFactoryImpl();
Still the same exception
true (The license file exists)
Exception in thread "main" net.sf.saxon.trans.LicenseException: License file saxon-license.lic not found. Tried in file:/E:/MySpace/lib/saxon-license.lic, and classpath. A license is needed to use schema processing
at com.saxonica.config.EnterpriseConfiguration.checkLicensedFeature(EnterpriseConfiguration.java:311)
at com.saxonica.ee.jaxp.SchemaFactoryImpl.(SchemaFactoryImpl.java:59)
at webdriver.test.SaxonTest.main(SaxonTest.java:40)
RE: Setting Licence Path through API
-
Added by Michael Kay almost 7 years ago
The problem is that the SchemaFactoryImpl you are creating is not associated with any Configuration, so it creates a new one. Try the constructor that accepts a Configuration as an argument.
RE: Setting Licence Path through API
-
Added by ozkan ozcan almost 7 years ago
That was it. It works now.
Thanks.
RE: Setting Licence Path through API
-
Added by ozkan ozcan almost 7 years ago
Hi Michael,
One more question regarding how to make the license file available in class path: I am using saxon in some utility classes which are packed as a jar to be used by web application. How can I wrap the license in a jar and make it available in class path. Copying it manually to the location where saxonee jar exists is not an option.
Thanks, Özkan
RE: Setting Licence Path through API
-
Added by Michael Kay almost 7 years ago
If you are packaging an application for distribution to a number of machines, then of course you need a license for each one of those machines: we don't actually mind if you use the same physical license file on each machine, so long as you have paid for enough units to cover your usage. There's a mechanism that dispenses with license files entirely, but this is only applicable to customers who purchase a redistribution license. It may be a good idea to have a commercial discussion about what your best options are, but we would want to do that by email rather than on a public forum.
I think we have tested that when you bundle a license file into a JAR file that is on the classpath, then Saxon will find it.
Please register to reply