Tag Archives: JDK11

OpenJDK11 failed: PKIX path building failed XXXXX

Prospect review

Because the company’s project needs, it needs to connect with Amazon IOT and send messages to Amazon IOT. It uses Amazon’s SDK. Everything seems normal. However, the test service reports an error and the local environment is normal.

Local JDK configuration:

java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

JDK configuration of test service:

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Is there a big difference?There is no big difference. Oracle jdk11 is used locally. The server uses openjdk11 because it knows why. That’s all, but the program will always report an error:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

solve the problem

First changed a configuration

Find a link, which is a link on the official website of Oracle. The description of Oracle certificate roughly means that Oracle JDK will no longer trust the TLS certificate issued by Symantec, which is consistent with the similar plans recently announced by Google, Mozilla, apple and Microsoft. If necessary, you can bypass these restrictions by commenting out or deleting “symantec_tls” in the jdk.security.cadisttrustpolicies security attribute of the java.security configuration file.

https://blogs.oracle.com/java/post/oracles-plan-for-distrusting-symantec-tls-certificates-in-the-jdk

The above configuration is in Java_ The file home/conf/security/java.security is opened in the form of text. It is around line 1187. There is such a sentence JDK. Security. Cadistrustpolicies = Symantec_ TLS needs to be commented out and changed to the following:

#jdk.security.caDistrustPolicies=SYMANTEC_ TLS

Then, then the server still can’t, Gan!

In the middle, I made a lot of attempts, but I didn’t describe it in detail. Finally, I was surprised and did a magical operation!

Then replaced a file

In Java_ Home/lib/security/cacerts file. This file is mainly a warehouse used by JDK to store certificates, including self trusted certificates and some certificates imported by keytool. Then I used Oracle cacerts certificate to replace the file with the same name under the same path of openjdk on the server. OK, done!

Problem estimation

Through the keytool – List – keystore cacerts command to view the two files, it is found that the date of the oreclejdk is irregular and the date is relatively long, while the date of the openjdk is 2021. I don’t know if it has anything to do with this problem. If I encounter it at present, I’ll remember it first and make a note.

Notes for migrating Oracle jdk8 to openjdk11

Java 8 upgrade Java 11

Because orcle stopped the free follow-up security update of jdk8, the decision to upgrade JDK to 11 was adopted after the decision.

Specific version:

current version

java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Target version

java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.2+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.2+9, mixed mode)

Upgrade process:

Download and install jdk11

JDK download
the selection of jdk11 version is: adptopen JDK 11.0.2 + 9
1 https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/tag/jdk-11.0.2+9
Download
https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B9/OpenJDK11U-jdk_ x64_ windows_ hotspot_ 11.0.2_ 9. Zip
latest or more versions: GitHub view all the released versions of open JDK (change the environment variable to jdk11, if you don’t start a java program such as Tomcat on the command line, you can skip this step, generally you don’t need to use ide on Windows)

Add jdk11: Ctrl Shift Alt + s — & gt; SDKs –> + Select JDK — & gt; Make sure that the compiler of the specified project in the directory is jdk11: Ctrl Shift Alt + S – & gt; Project ——> The project SDK and project SDK level are changed to the newly added 11, and the rest remain unchanged (the project is controlled by Maven’s pom.xml)
update the project compiler to jdk11pom.xml. See the following for the detailed process

Pom.xml transformation

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>11</release>
    </configuration>
</plugin> 

This plug-in is used to compile the source code; The configuration in it represents the use of 11 to compile

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.22.0</version>
    <configuration>
        <argLine>
            --illegal-access=permit
        </argLine>
    </configuration>
</plugin>

Surefire plug-in is used to execute unit test of an application in the test phase of Maven build life cycle. It will produce two different forms of test results

<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.23.1-GA</version>
</dependency>

The questions are listed as follows:

if the method provided in this paper can not be solved, you can try the following </ H6>
    1. clean the whole project/project and recompile it with Java 11
    1. in idea:
    1. build — build artifacts — all — clean
    1. build — build artifacts — all — build delete the corresponding components under Tomcat/webapps (clear the cache) </ OL>

Question 1

Symptom
resource cannot be resolved to a type
javax. Annotation. Resource
cause
resource class cannot be found; Java 11 has been removed as an alternative solution

Solutions

Add in pom.xml:

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.1</version>
</dependency>

Reference from stack overflow


Question 2

E rror:java : symbol not found
symbol: class resource
location: package javax.annotation

Solution:

        <dependency>
			<groupId>javax.annotation</groupId>
			<artifactId>javax.annotation-api</artifactId>
			<version>1.3.1</version>
		</dependency>   


Question 3

JAXB (Java. XML. Bind) problems are as follows:

Error:(10, 33) java: Package javax.xml.bind.annotation does not exist
Error:(24, 2) java: Symbol not found
  Symbol: Class XmlRootElement
Error:(28, 6) java: Symbol not found
  Symbol: Class XmlElement
  Location: Class com.xxx.xxx.xxxx.xxx.entity.xxx
  .....

Reasons
openjdk11 has deleted some packages. The following is an announcement:

Removal Of Java EE Modules
There used to be a lot of code in Java SE that was actually related to Java EE. It ended up in six modules that were deprecated for removal in Java 9 and removed from Java 11. Here are the removed technologies and packages:)
 
 
the JavaBeans Activation Framework (JAF) in javax.activation
CORBA in the packages javax.activity, javax.rmi, javax.rmi.CORBA, and org.omg.*
the Java Transaction API (JTA) in the package javax.transaction
JAXB in the packages javax.xml.bind.*   ############ This package is the cause of the problem
JAX-WS in the packages javax.jws, javax.jws.soap, javax.xml.soap, and javax.xml.ws.*
Commons Annotation in the package javax.annotation

The corresponding version is as follows:

<!-- Java 6 = JAXB version 2.0   -->
<!-- Java 7 = JAXB version 2.2.3 -->
<!-- Java 8 = JAXB version 2.2.8 -->
<!-- Java 9 = JAXB version 2.3.0 -->

Note: before the project is which version of JDK to introduce which version, for example, I was java8, so I want to introduce the JAXB version of 2.2.8

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.8</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.8</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.8</version>
</dependency>

Reference from stack overflow


Question 4

Warning: (54,44) newinstance() in Java: Java. Lang. class is obsolete

Solution:

Check the source code of newinstance() in open JDK 11 Java. Lang. class. Some comments are as follows

    /* can be replaced by
     *
     * <pre>{@code
     * clazz.getDeclaredConstructor().newInstance()
     *}</pre>
     */

It can be replaced by the above method

clazz.newInstance();

replace with

clazz.getDeclaredConstructor().newInstance();

Question 5
After starting Tomcat
Artifact upm-web:war: Error during artifact deployment. See server log for details.
View the logs as follows.

19-Mar-2019 09:50:31.061 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class [com.xxx.xxx.xxx.WebContextLoaderListener]
 java.lang.UnsupportedClassVersionError: com/xxx/xxx/xxx/WebContextLoaderListener has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [com.xxx.xxx.xxx.WebContextLoaderListener])
	at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2377)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:846)
	...
19-Mar-2019 09:50:31.061 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Skipped installing application listeners due to previous error(s)

Reason
according to the description of exception information (unsupported version of XXX. Class), it means that the current class version to be loaded is 55 (Java 11), which cannot be loaded. The current Java runtime supports 52 (Java 8) versions of. Class files at most
where the java version corresponds to the class version as follows:

J2SE 11 = 55 (0x33 hex),
J2SE 10 = 54 (0x33 hex),
J2SE 9 = 53 (0x33 hex),
J2SE 8 = 52 (0x33 hex),
J2SE 7 = 51 (0x33 hex),
J2SE 6.0 = 50 (0x32 hex),
J2SE 5.0 = 49 (0x31 hex),
JDK 1.4 = 48 (0x30 hex),
JDK 1.3 = 47 (0x2F hex),
JDK 1.2 = 46 (0x2E hex),
JDK 1.1 = 45 (0x2D hex).

It can be seen that the actual cause of the problem is that the program compiled by java8 (Tomcat) calls the program compiled by java11.

Solution:

Using higher version Tomcat 9

Detailed process:

Go to Tomcat official website to download tomcat9, unzip the downloaded zip (modify the Tomcat environment variable and do not use it in the command line, which can be skipped). Modify the Tomcat set in IDE to the newly installed tomcat9. Take idea as an example:

Run edit configurations on the top right — configure on the right side of application server… Click on the top left + add the file location of newly installed tomcat9, OK, confirm to save the modification below, change JRE to newly added JDK 11, save the settings (note whether there are errors in the prompt area below) and run to check whether the configuration is correct


The above is my JDK version upgrade problems. Welcome to add!

Jdk11, using JavaFX in eclipse

Eclipse Version: 2018-12 (4.10.0)
JDK Version 11.0.2
Windows 64
First of all, the official documentation for JavaFX,
, is very detailed, and this article does not follow it exactly.
Download an appropriate JavaFX runtime Download an appropriate JavaFX runtime extract to folder (location not fixed but remember path), for example:
D:\openjfx-11.0.2_windows-x64_bin-sdk\javafx-sdk-11.0.2"
2. Ecliplse has been downloaded by default and Java11.0.2 development environment has been configured. Note that since Java11, the JDK and javaFX have been separated (there is no jre package for javaFX in the JDK after exporting the jre folder from the command line), so you don’t have to download a e(fx)clipse plug-in to use, you have to download and add it manually.
3. Create a User Library according to the official document. Include the jre under lib in the JavaFX runtime file downloaded before
Eclipse -> Window -> Preferences -> Java -> Build Path -> User Libraries -> New
next name is arbitrary, you can find the added FX lib in the Library when creating the project
4. Create a Java project, need three files, (someone else’s Github project link), and import a custom Library path.
5. The following problem occurs in the runtime. The solution mentioned in the official document is to add VM parameters
run-& gt; Run Configurations... select Main. Java is the Main class also click the Arguments TAB you can see the Arguments of the VM option, add the following parameters
- the module - the path "/ path/to \ \ lib" deployment headaches - SDK - 11 - add - modules deployment headaches. Controls, deployment headaches. FXML
Here, the path, to 11 \ lib \ deployment headaches - SDK - parameter is the path of the openjfx before download file decompression, such as
- the module - path "D: \ eclipse \ openjfx - 11.0.2 _windows x64_bin - SDK \ deployment headaches - SDK - 11.0.2 \ lib" - add - modules deployment headaches. Controls, deployment headaches. FXML
The successful running
The import Javafx cannot be resolved
JavaFX Runtime Components are missing, and are required to run this application
Problem 3. Error: The Main class Application.main cannot be initialized
As for the first problem, it is probably due to the
problem caused by running javaFX in the way of installing plug-ins when Java11 JDK and javaFX are separated at the beginning. If there is a problem with the import of Library package, check the path or go directly into the path to see if all of these jre files exist.