从jdk1.8升级到jdk17踩过的所有坑的总结
再运行maven命令之前,加入下面vm参数,英文exec-maven-plugin运行的时候不是独立的jvm process.如果是运行maven命令时报错,升级maven-compiler-plugin并加下面vm的参数。既不能升级sybDriver也不能fix , 最后只能remove了。Garbage Collector不能用了。如果是启动报错的话直接下面所有的vm的参数。升级gmaven-
目录
1. java.lang.reflect.InaccessibleObjectException:
2. java.lang.UnsatisfiedLinkError in autosys
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
12. java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long
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
11. java.lang.ClassCastException: class java.lang.String cannot be cast to class Enum (java.lang.String is in module java.base of loader 'bootstrap'
错我信息
Exception in thread "main" java.lang.ClassCastException: class java.lang.String cannot be cast to class WorkFlow (java.lang.String is in module java.base of loader 'bootstrap'; WorkFlow is in unnamed module of loader 'app')
at JdkError.main(JdkError.java:15)
示例代码
项目中的枚举类不能从String强转过来了,因为它在nnnamed module of loader 'app'
public class JdkError {
public static void main(String[] args) {
String workflow = WorkFlow.POST_EVENT_APPROVAL_FLOW.toString();
Object workflowObject = workflow;
workEnum = (WorkFlow)workflowObject;
}
}
enum WorkFlow {
POST_EVENT_APPROVAL_FLOW, POST_PU_APPROVAL_FLOW, ELECTION_FLOW
};
解决方法:
调用枚举类中valueof把String转为Enum
WorkFlow workEnum = WorkFlow.valueOf(workflowObject.toString());
System.out.println(workEnum);;
12. java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
示例代码
Integer annId = 1;
// 中间可能是在什么地方把它转成Object类型了
Object annIdObject = annId;
System.out.println((long) annIdObject);
解决方法
写一个方法把这个Object转换为Integer.
public static Integer convertToInteger(Object obj){
if (obj instanceof Long){
return Long.valueOf(obj.toString()).intValue();
}else if (obj instanceof Integer){
return Integer.valueOf(obj.toString());
}
return (Integer)obj;
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)