大家好,又见面了,我是全栈君。
问题描写叙述
遇到的问题是在weblogic环境,应用在上传图片的时候报Could not initialize class sun.awt.X11.XToolkit 错误。
详细错误例如以下
17:57:02 [AWT-EventQueue-2] DEBUG - Leaving class nc.ui.hi.psndoc.action.SavePsndocAction.actionPerformed Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at java.awt.Toolkit$2.run(Toolkit.java:834) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826) at javax.swing.ImageIcon.<init>(ImageIcon.java:236) at nc.pub.tools.VOUtils.transPreviewPhoto(VOUtils.java:212) at nc.impl.hi.psndoc.PsndocValidator.setPreviewPhoto(PsndocValidator.java:1338) at nc.impl.hi.psndoc.PsndocValidator.adjustPsndoc(PsndocValidator.java:1320) at nc.impl.hi.psndoc.PsndocValidator.validate(PsndocValidator.java:819) at nc.impl.hi.psndoc.PsndocServiceImpl.savePsndoc(PsndocServiceImpl.java:1616) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint$3.invoke(MethodProceedingJoinpoint.java:74) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint.proceed(MethodProceedingJoinpoint.java:184) at nc.bs.framework.server.SecurityAspect.aroundMethod1(SecurityAspect.java:45) at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at nc.bs.framework.aop.rt.AdviceHolder.invoke(AdviceHolder.java:182) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint.proceed(MethodProceedingJoinpoint.java:129) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint.proceed(MethodProceedingJoinpoint.java:135) at nc.bs.aop.log.BusilogAspect.aroundMethod(BusilogAspect.java:75) at sun.reflect.GeneratedMethodAccessor1769.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at nc.bs.framework.aop.rt.AdviceHolder.invoke(AdviceHolder.java:182) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint.proceed(MethodProceedingJoinpoint.java:129) at nc.bs.framework.aop.rt.MethodProceedingJoinpoint.proceed(MethodProceedingJoinpoint.java:135) at nc.bs.framework.aop.rt.AspectedProxy.invoke(AspectedProxy.java:59) at $Proxy519.savePsndoc(Unknown Source) at nc.itf.hr.hi.HRhiEJBEjbBean.savePsndoc(HRhiEJBEjbBean.java:2812) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37) at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54) at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy514.savePsndoc(Unknown Source)
解决的方法
在启动javaserver的时候。在启动參数中增加下面參数
-Djava.awt.headless=true
headless问题探讨
关于javaserver的headless模式。oracle官网的说明为:
http://www.oracle.com/technetwork/articles/javase/headless-136834.html
当中非常多概念我也不是非常理解
大致意思就是,在javaserver端,有很多图形界面的处理函数。须要调用显示器,鼠标键盘这些设备,但有些处理函数则不须要。假设设置了这个headless之后。图形界面的处理和渲染是分开的,用于生成图片的工作放在server端进行,生成后将编码传到client,再在client进行渲染和显示。
这主要用了server端的高计算能力。然后把须要调用显示器相关的工作传到client去运行。
以上的错误本身是要初始化X11server。然后用X11的工具箱去做图形生成计算这等事。可是X11初始化失败。应该是X11的安装环境有问题,于是能够设置java參数
-Djava.awt.headless=true
这个參数。使用java自带的这个server工具箱。
以上是我的理解,对错有待验证。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116438.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...