Difference between revisions of "Java8"

From BITPlan Wiki
Jump to navigation Jump to search
(18 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
* Because Java 10 breaks more things
 
* Because Java 10 breaks more things
 
* Because Java 11 breaks even more things
 
* Because Java 11 breaks even more things
 +
* Because Java >=12 will surely break more of the stuff that has been working perfectly for years
 
And the cost/benefit relation of moving along Oracle's ideas seems not worthwile.
 
And the cost/benefit relation of moving along Oracle's ideas seems not worthwile.
  
Line 8: Line 9:
 
== Mediawiki-Japi ==
 
== Mediawiki-Japi ==
 
* [https://travis-ci.org/WolfgangFahl/Mediawiki-Japi/builds/595988729?utm_medium=notification&utm_source=email Travis build suddenly fails]
 
* [https://travis-ci.org/WolfgangFahl/Mediawiki-Japi/builds/595988729?utm_medium=notification&utm_source=email Travis build suddenly fails]
 +
=== Problem ===
 +
<source lang='bash'>
 +
Mediawiki-Japi/src/main/java/com/bitplan/mediawiki/japi/api/Page.java:[34,33] package javax.xml.bind.annotation does not exist
 +
</source>
 +
=== Diagnosis ===
 +
* https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j
 +
Oracle decided to remove APIs
 +
 +
=== Solution ===
 +
Do not use Oracle's incompatible Java versions - stay with Version 8
 +
<source lang='yaml'>
 +
diff --git a/.travis.yml b/.travis.yml
 +
# this is a java project using maven
 +
language: java
 +
+# make sure things keep working see http://wiki.bitplan.com/index.php/Java8
 +
+jdk: openjdk8
 +
</source>
 +
 +
== Crashing Eclipse ==
 +
=== Problem ===
 +
Trying to start Eclipse oxygen leads to multiple ClassNotFoundExceptions
 +
=== Diagnosis ===
 +
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=533390
 +
* https://stackoverflow.com/questions/48349760/how-do-i-change-my-eclipse-ides-launch-jvm
  
 +
=== Therapy ===
 +
Surprise - stay with Java 8 ...
 +
Search it:
 
<source lang='bash'>
 
<source lang='bash'>
Mediawiki-Japi/src/main/java/com/bitplan/mediawiki/japi/api/Page.java:[34,33] package javax.xml.bind.annotation does not exist
+
/usr/libexec/java_home -v 1.8
 +
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home
 +
</source>
 +
and add it to your eclipse.ini (make sure using two lines as below ...
 +
<pre>
 +
-vm
 +
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/bin/java
 +
</pre>
 +
== Hazelcast not starting properly ==
 +
=== Problem ===
 +
<pre>
 +
java: WARNING: Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:
 +
 
 +
java:  --add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED
 +
</pre>
 +
and then it doesn't work / the tcp connections fail
 +
=== Diagnosis ===
 +
Code not working without changes
 +
=== Therapy ===
 +
Surprise - stay with Java 8 ...
 +
== Incompatible Javadoc ==
 +
=== Problem ===
 +
<pre>
 +
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.1:jar (attach-javadocs) on project com.bitplan.rest.freemarker: MavenReportException: Error while generating Javadoc:
 +
 
 +
[ERROR] Exit code: 1 - javadoc: error - The code being documented uses modules but the packages defined in https://docs.oracle.com/javase/8/docs/api/ are in the unnamed module.
 +
 
 +
[ERROR]
 +
 
 +
[ERROR] Command line was: /usr/local/lib/jvm/openjdk11/bin/javadoc -Xdoclint:none @options @packages
 +
</pre>
 +
=== Diagnosis ===
 +
<source lang='bash'>
 +
java -Xmx32m -version
 +
 
 +
openjdk version "11.0.2" 2019-01-15
 
</source>
 
</source>
 +
Java 11 javadoc is incompatible to prior versions
 +
=== Therapy ===
 +
Surprise - stay with Java 8 ...
 +
== mvn site fails ==
 +
=== Problem ===
 +
<pre>
 +
org.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19
 +
    at org.apache.bcel.classfile.Constant.readConstant (Constant.java:161)
 +
</pre>
 +
=== Diagnosis ===
 +
* https://stackoverflow.com/questions/49383179/org-apache-bcel-classfile-classformatexception-invalid-byte-tag-in-constant-poo
 +
* upgrading maven site plugin to https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin/3.9.0 does not help
 +
 +
=== Therapy ===

Revision as of 12:09, 16 March 2020

Why Java 8 is not dead

  • Because Java 9 breaks things
  • Because Java 10 breaks more things
  • Because Java 11 breaks even more things
  • Because Java >=12 will surely break more of the stuff that has been working perfectly for years

And the cost/benefit relation of moving along Oracle's ideas seems not worthwile.

Examples

Mediawiki-Japi

Problem

Mediawiki-Japi/src/main/java/com/bitplan/mediawiki/japi/api/Page.java:[34,33] package javax.xml.bind.annotation does not exist

Diagnosis

Oracle decided to remove APIs

Solution

Do not use Oracle's incompatible Java versions - stay with Version 8

diff --git a/.travis.yml b/.travis.yml
 # this is a java project using maven
 language: java
+# make sure things keep working see http://wiki.bitplan.com/index.php/Java8
+jdk: openjdk8

Crashing Eclipse

Problem

Trying to start Eclipse oxygen leads to multiple ClassNotFoundExceptions

Diagnosis

Therapy

Surprise - stay with Java 8 ... Search it:

/usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home

and add it to your eclipse.ini (make sure using two lines as below ...

-vm
/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/bin/java

Hazelcast not starting properly

Problem

java: WARNING: Hazelcast is starting in a Java modular environment (Java 9 and newer) but without proper access to required Java packages. Use additional Java arguments to provide Hazelcast access to Java internal API. The internal API access is used to get the best performance results. Arguments to be used:

java:  --add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED

and then it doesn't work / the tcp connections fail

Diagnosis

Code not working without changes

Therapy

Surprise - stay with Java 8 ...

Incompatible Javadoc

Problem

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.1:jar (attach-javadocs) on project com.bitplan.rest.freemarker: MavenReportException: Error while generating Javadoc: 

[ERROR] Exit code: 1 - javadoc: error - The code being documented uses modules but the packages defined in https://docs.oracle.com/javase/8/docs/api/ are in the unnamed module.

[ERROR] 

[ERROR] Command line was: /usr/local/lib/jvm/openjdk11/bin/javadoc -Xdoclint:none @options @packages

Diagnosis

java -Xmx32m -version

openjdk version "11.0.2" 2019-01-15

Java 11 javadoc is incompatible to prior versions

Therapy

Surprise - stay with Java 8 ...

mvn site fails

Problem

org.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 19
    at org.apache.bcel.classfile.Constant.readConstant (Constant.java:161)

Diagnosis

Therapy