从jdk1.8升级到jdk17踩过的所有坑的总结

目录

1. java.lang.reflect.InaccessibleObjectException:

2. java.lang.UnsatisfiedLinkError in autosys

3.  java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

4. java.lang.UnsatisfiedLinkError: ***/lib/libfontmanager.so: libfreetype.so.6

5. his method is deprecated and marked for removal. Use the getPeerCertificates() method instead.

6. Could not initialize class com.sybase.jdbc4.jdbc.SybDriver

7. Unrecognized VM option 'UseParNewGC'

8. Failed to execute goal org.codehaus.groovy.maven:gmaven-plugin:1.0

9.  Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.9:

10.InaccessibleObjectException while executing exec-maven-plugin


1. java.lang.reflect.InaccessibleObjectException:

异常:

java.lang.reflect.InaccessibleObjectException: Unable to make java.lang.String(char[],int,int,java.lang.Void) accessible: module java.base does not "opens java.lang" to unnamed module

解决方法:

加下面参数

--add-opens= java.base/java.lang=ALL-UNNAMED

如果是启动报错的话直接下面所有的vm的参数

export _JAVA_OPTIONS="$_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.math=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.net=ALL-UNNAMED --add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED"

如果是运行maven命令时报错,升级maven-compiler-plugin并加下面vm的参数

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.8.0</version>
   <configuration>
      <source>${java.version}</source>
      <target>${java.version}</target>
      <compilerArgs>
         <arg>--add-exports</arg><arg>java.base/java.lang=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/java.io=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/java.util=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/java.lang.reflect=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/java.math=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/java.nio=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/sun.security=ALL-UNNAMED</arg>
         <arg>--add-exports</arg><arg>java.base/sun.net=ALL-UNNAMED</arg>
      </compilerArgs>
   </configuration>
</plugin>

2. java.lang.UnsatisfiedLinkError in autosys

异常:

Error: A JNI error has occurred, please check your installation and try again

Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/jdk/17.0_6l64/lib/libnio.so: /opt/jdk/17.0_6l64/lib/libjava.so: version `SUNWprivate_1.1' not found (required by /opt/CA/WorkloadAutomationAE/SystemAgent/WA1_AGENT/jre/lib/amd64/libnet.so)

解决方法:

export PATH=/opt/jdk/latest/bin:$PATH

export LD_LIBRARY_PATH=/opt/jdk/latest/lib:$LD_LIBRARY_PATH

3.  java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

解决方法:

-Djava.io.tmpdir=/yourdirectory/tmp

4. java.lang.UnsatisfiedLinkError: ***/lib/libfontmanager.so: libfreetype.so.6

异常:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/***] threw exception [Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: ***/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory] with root cause
java.lang.UnsatisfiedLinkError: ***/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory

解决方法:

yum -y install freetype&&\
yum-y install fontconfig

5. his method is deprecated and marked for removal. Use the getPeerCertificates() method instead.

异常:

java.lang.UnsupportedOperationException: This method is deprecated and marked for removal. Use the getPeerCertificates() method instead.

               at java.base/javax.net.ssl.SSLSession.getPeerCertificateChain(SSLSession.java:295)

               at java.base/javax.net.ssl.HandshakeCompletedEvent.getPeerCertificateChain(HandshakeCompletedEvent.java:173)

解决方法:

升级下面jar

<dependency>
	<groupId>com.ibm.mq</groupId>
	<artifactId>com.ibm.mq.allclient</artifactId>
          	<version>9.2.4.0</version>
</dependency>

6. Could not initialize class com.sybase.jdbc4.jdbc.SybDriver

异常:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.sybase.jdbc4.jdbc.SybDriver

at java.lang.Class.forName0(Native Method) ~[?:?]

at java.lang.Class.forName(Class.java:467) ~[?:?]

at java.sql.DriverManager.isDriverAllowed(DriverManager.java:558) ~[java.sql:?]

at java.sql.DriverManager.isDriverAllowed(DriverManager.java:550) ~[java.sql:?]

at java.sql.DriverManager.getDrivers(DriverManager.java:451) ~[java.sql:?]

解决方法:

没有好的解决方法。既不能升级sybDriver也不能fix , 最后只能remove了。

7. Unrecognized VM option 'UseParNewGC'

异常:
Unrecognized VM option 'UseParNewGC'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Unrecognized VM option 'UseConcMarkSweepGC'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Error: Could not find or load main class XX:+AlwaysPreTouch
Caused by: java.lang.ClassNotFoundException: XX:+AlwaysPreTouch

Unrecognized VM option 'UseCMSInitiatingOccupancyOnly'

解决方法:

删掉这些参数,因为CMS Garbage Collector不能用了。

8. Failed to execute goal org.codehaus.groovy.maven:gmaven-plugin:1.0

[ERROR] Failed to execute goal org.codehaus.groovy.maven:gmaven-plugin:1.0:execute (default-cli) on project aspen-positions-core: java.lang.reflect.InaccessibleObjectException: Unable to make java.lang.String(char[],int,int,java.lang.Void) accessible: module java.base does not "opens java.lang" to unnamed module @2e2ccf82 -> [Help 1]

解决方法:

升级gmaven-plugin.

<plugin>
 <groupId>org.codehaus.gmavenplus</groupId>
 <artifactId>gmavenplus-plugin</artifactId> 
 <version>3.0.0</version>
....
</plugin>

9.  Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.9:

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.9:compile (default) on project aspen-positions-web: Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.9:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.9 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:17.0.5 at specified path C:\apps\jdk-17.0.5/../lib/tools.jar -> [Help 1]

解决方法:

升级aspectj-maven-plugin注意要把dependency全去掉

<plugin>
      <groupId>dev.aspectj</groupId>
       <artifactId>aspectj-maven-plugin</artifactId>
       <version>1.13.1</version>
                     .........
 </plugin>

10.InaccessibleObjectException while executing exec-maven-plugin

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>3.1.0</version>
<plugin>

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @5aea386f

解决方法:

再运行maven命令之前,加入下面vm参数,英文exec-maven-plugin运行的时候不是独立的jvm process.

MAVEN_OPTS=--add-opens=java.base/java.lang=ALL-UNNAMED

猜你喜欢

转载自blog.csdn.net/keeppractice/article/details/132747738