Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to interrogate a JVM/JRE for its license?

Tags:

java

Oracle changed the license for its Java releases:

  • 8u201/8u202 and prior: Oracle Binary Code License (OBCL) Agreement
  • 8u211/8u212 and later: Oracle Technology Network (OTN) License Agreement

I suppose that all Oracle releases of Java 7 and below were OBCL; I'm not sure if there were any Oracle Java 9+ releases under that old license.

Of course, other Java distributions (OpenJDK, etc.) have still other licenses.

Is there a way for a running program to determine the license of the underlying JVM/JRE? Motivation: I'd like to warn users of my program when they're using my program on a JVM/JRE of specific license(s).

I've been unable find to find any standard system property with this information, and I also looked in the manifests of the JARs that constitute the JRE.

There are a couple places that provide structured access to the Java version:

  • https://commons.apache.org/proper/commons-lang/javadocs/api-3.9/org/apache/commons/lang3/SystemUtils.html → IS_JAVA_1_8, etc.
  • https://commons.apache.org/proper/commons-lang/javadocs/api-3.9/org/apache/commons/lang3/JavaVersion.html
  • https://docs.oracle.com/javase/9/docs/api/java/lang/Runtime.Version.html

The former doesn't get down to the detail of the the update number, and the latter is only available in Java 9+. In any case, both still require some other resource to map known Java versions to their respective licenses.

Also: I'm aware of Oracle's latest recommendation of bundling a JRE with one's application, and that this issue can be avoided that way.

like image 370
Robert Fleming Avatar asked Sep 05 '19 05:09

Robert Fleming


People also ask

Does Java JRE need to be licensed?

Redistribution of the Java SE Runtime Environment (JRE)Current releases of the Oracle Java SE 8 Runtime Environment require a commercial license for redistribution.

Is Java Runtime free for commercial use?

Oracle has announced that from January 2019, Java SE 8 public updates will no longer be available for business, commercial or production use without a commercial license although it will remain free for general purpose computing usage.

Does Java JDK require a license?

Oracle previously released these older versions as free public updates. The Oracle Java license change kicks in for Java 11 and later. With these releases, Oracle now requires a commercial subscription for the use of the Oracle Java Runtime Environment.

How does Java licensing work?

What is the New Java SE Licensing Structure? Under this new model, customers will no longer purchase licenses upfront and pay annual support for Java SE. Instead, they will pay a monthly subscription fee under one to three-year terms for server or desktop licensing and support.


1 Answers

${java.home}/LICENSE

Oracle Java 7 and 8 contain a file ${java.home}/LICENSE. For 1.7.0_80 and 1.8.0_152, the content is:

Please refer to http://java.com/license

After 6 HTTP redirects, that currently leads to https://www.oracle.com/downloads/licenses/binary-code-license.html, which describes "Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX."

${java.home}/LICENSE in Oracle Java 1.8.0_221 says:

Please refer to https://java.com/bc_license

After 3 HTTP redirects, that currently leads to https://www.oracle.com/downloads/licenses/javase-license1.html, which describes "Oracle Technology Network License Agreement for Oracle Java SE."

${java.home}/LICENSE in Oracle Java 1.8.0_251 says:

Please refer to https://java.com/otnlicense

Oracle and OpenJDK Java releases 9+ don't provide ${java.home}/LICENSE.

${java.home}/release

All Java releases have a file ${java.home}/release, which looks like this for Oracle Java 11:

BUILD_TYPE="commercial"
IMPLEMENTOR="Oracle Corporation"
...

and this for Ubuntu's openjdk-11-jre-headless package (version 11.0.4+11-1ubuntu2~18.04.3):

IMPLEMENTOR="Ubuntu"
...

There is no BUILD_TYPE value in the case of the Ubuntu package.

Other results with downloads from java.net:

jre-8u221-linux-i586.tar.gz and jdk-8u251-linux-i586.tar.gz :

BUILD_TYPE="commercial"

jdk-9+181_linux-x64_ri.zip:

IMPLEMENTOR="N/A"

serverjre-9_linux-x64_bin.tar.gz (java -version says build 9+181):

BUILD_TYPE="commercial"
IMPLEMENTOR="Oracle Corporation"

openjdk-10+44_linux-x64_bin_ri.tar.gz:

IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION_DATE="2018-03-20"

jdk-10_linux-x64_bin_ri.tar.gz (java -version says build 10+44):

IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION_DATE="2018-03-20"

openjdk-11+28_linux-x64_bin.tar.gz:

IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION_DATE="2018-09-25"

jdk-11.0.4_linux-x64_bin.tar.gz:

BUILD_TYPE="commercial"
IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION_DATE="2019-07-16"

openjdk-12.0.2_linux-x64_bin.tar.gz:

IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION_DATE="2019-07-16"

Oracle Java 7 and 8 installed on Ubuntu via the oracle-java7-installer and oracle-java8-installer packages also provide ${java.home}/release, containing:

BUILD_TYPE="commercial"

${java.home}/legal/java.base/LICENSE

Java 9+ distributions contain a ${java.home}/legal directory. Examining ${java.home}/legal/java.base/LICENSE:

  • openjdk-9+181_linux-x64_ri.zip: GPLv2 + classpath exception
  • jdk-9+181_linux-x64_ri.zip: GPLv2 + classpath exception
  • serverjre-9_linux-x64_bin.tar.gz: "Please refer to http://java.com/license"
  • openjdk-10+44_linux-x64_bin_ri.tar.gz: GPLv2 + classpath exception
  • jdk-10_linux-x64_bin_ri.tar.gz: GPLv2 + classpath exception
  • openjdk-11+28_linux-x64_bin.tar.gz: GPLv2 + classpath exception (legal/*/LICENSE are identical)
  • jdk-11.0.4_linux-x64_bin.tar.gz: "Please refer to https://java.com/otnlicense" (legal/*/LICENSE are identical)
  • openjdk-12.0.2_linux-x64_bin.tar.gz: GPLv2 + classpath exception

Ubuntu's openjdk-11-jre-headless 11.0.4+11-1ubuntu2~18.04.3 provides no ${java.home}/legal/*/LICENSE.

Summary

Strangely, it looks like "https://java.com/bc_license" in ${java.home}/LICENSE is a good indication of an OTN-licensed JRE. I suppose it was a mistake that for Oracle releases after March 16, 2019, the URL in LICENSE changed from "http://java.com/license" to "https://java.com/bc_license"; they should have changed it to "https://java.com/otnlicense". Their remedy was to make https://java.com/bc_license redirect to the OTN document.

A strong hint is when ${java.home}/legal/java.base/LICENSE contains "Please refer to https://java.com/otnlicense".

A weaker hint is the combination of:

  • IMPLEMENTOR="Oracle Corporation",
  • BUILD_TYPE="commercial", and
  • JAVA_VERSION_DATE="2019-04-16" or later.

More robust answers welcome though!

like image 95
8 revs Avatar answered Oct 10 '22 07:10

8 revs