在Tomcat上访问GraphicsEnvironment.getLocalGraphicsEnvironment时发生NoClassDefFoundError [英] NoClassDefFoundError while accessing GraphicsEnvironment.getLocalGraphicsEnvironment on Tomcat

查看:234
本文介绍了在Tomcat上访问GraphicsEnvironment.getLocalGraphicsEnvironment时发生NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在tomcat上运行的应用程序,方法之一是从jpeg图像创建一个简单的缩略图.该功能可以在离线环境下正常运行,一周前也可以在tomcat上运行.但是现在我收到以下错误:

java.lang.NoClassDefFoundError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
eval.impl.ImageEval.getThumbnail(ImageEval.java:155)
eval.impl.ImageServlet.doGet(ImageServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

我不认为我有任何改变会影响它的东西(实际上我并没有根据svn存储库完全改变功能),因此它一定是库问题.但是我不知道缺少了什么. 这是发生错误的getThumbnail函数的实际行:

        BufferedImage thumbImage = new BufferedImage(thumbWidth, 
            thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(simage, 0, 0, thumbWidth, thumbHeight, null);

[edit]我决定对问题描述进行一些更新. 是的,似乎他无法从java.awt中找到某个类或与此相关的类.但是它们确实存在于jvm的服务器上. Java无头模式无法解决问题. 在另一个项目中,代码完全相同,但是在此服务器上的axis2 Web服务内部运行正常. [/edit]

解决方案

似乎您已经更改了Tomcat的配置.

您已更改为l {0,1} nxx盒,或已安装在具有与测试安全性不同的安全控制的虚拟机上.

显然是

 GraphicsEnvironment.getLocalGraphicsEnvironment()

正在尝试访问属性: java.awt.graphicsenv

可能返回null或某些不存在的类名,然后将其加载并引发ClassNotFoundException. 1

该解决方案似乎正在指定"java.awt.headless"属性.

这是一个类似的问题: java.awt.Color错误

尝试以下 GraphicsEnvironment.java

编辑

这不是日食!

在我的原始帖子中,有一个指向引发异常的类源代码的链接.

因为我看起来像您想念它,所以我会在这里为您发布:

       public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
          if (localEnv == null) {
               // Y O U R   E R R O R  O R I G I N A T E S    H E R E !!! 
              String nm = (String) java.security.AccessController.doPrivileged
                  (new sun.security.action.GetPropertyAction
                   ("java.awt.graphicsenv", null));

              try {
  //                      long t0 = System.currentTimeMillis();
                  localEnv =
                      (GraphicsEnvironment) Class.forName(nm).newInstance();
  //              long t1 = System.currentTimeMillis();
  //              System.out.println("GE creation took " + (t1-t0)+ "ms.");
                  if (isHeadless()) {
                      localEnv = new HeadlessGraphicsEnvironment(localEnv);
                  }
              } catch (ClassNotFoundException e) {
                  throw new Error("Could not find class: "+nm);
              } catch (InstantiationException e) {
                  throw new Error("Could not instantiate Graphics Environment: "
                                  + nm);
              } catch (IllegalAccessException e) {
                  throw new Error ("Could not access Graphics Environment: "
                                   + nm);
              }
          }

          return localEnv;
      }

这就是执行的内容.

在您似乎没有看过的原始帖子中,我说过代码正在访问属性"java.awt.graphicsenv"

如果其他使用axis的项目没有相同的问题,则可能是因为它可能是在不同的tomcat配置中运行,或者是Axis库允许访问该属性.但是我们不能确定.那纯粹是猜测.那么,为什么不测试以下内容并查看打印出来的内容:

        String nm = (String) java.security.AccessController.doPrivileged
            (new sun.security.action.GetPropertyAction
             ("java.awt.graphicsenv", null));

    System.out.println("java.awt.graphicsenv = " + nm );

它打印为null,然后您现在是什么问题.您的系统中没有该属性,或者安全性禁止您使用它.

从这里很难告诉您:去编辑文件xyz并添加:fail = false ",因此您必须做好工作并找出真正的原因.

首先研究正在执行的代码是什么(我刚刚发布了代码),然后了解它的作用以及"AccessController.doPrivileged"的所有工作方式. (您可以为此使用Google + StackOverflow).

I have an application which is running on tomcat, one of the methods is, creating a simple thumbnail from an jpeg image. The functions works fine offline and a week ago also on tomcat. But now i get the following error:

java.lang.NoClassDefFoundError
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
eval.impl.ImageEval.getThumbnail(ImageEval.java:155)
eval.impl.ImageServlet.doGet(ImageServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

I don't think that i have change anything what should influence this (actually i didn't change the function at all according to the svn repository), so it must be a library problem. But i can't figure out what is missing. Here are the actual lines from the getThumbnail function, where the error occures:

        BufferedImage thumbImage = new BufferedImage(thumbWidth, 
            thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(simage, 0, 0, thumbWidth, thumbHeight, null);

[edit] I decided to update the problem description a little. Yes it seems that he can not find some class from java.awt or one related to that. But they do exist on the server in the jvm. Java headless mode doesn't solve the problem. In another project the exact same code, but inside an axis2 webservice on this server is working fine. [/edit]

解决方案

It seems like you've change the configuration of Tomcat.

Either you've changed to a l{0,1}[iu]n[iu]x box or installed on a virtual machine with different security control than the one where you test it.

Apparently the

 GraphicsEnvironment.getLocalGraphicsEnvironment()

Is trying to access the property: java.awt.graphicsenv

Which may return null or some non existing class name which is then loaded and throws the ClassNotFoundException. 1

The solution seems to be specifying the "java.awt.headless" property.

This is a similar question: java.awt.Color error

Try this search , it shows similar situations as your.

I remember there was something in the sun bugs database too.

Post the solution when you find it!

1.GraphicsEnvironment.java

EDIT

It is not eclipse!!

In my original post there is a link to the source code of the class which is throwing the exception.

Since I looks like you miss it, I'll post it here for you:

       public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
          if (localEnv == null) {
               // Y O U R   E R R O R  O R I G I N A T E S    H E R E !!! 
              String nm = (String) java.security.AccessController.doPrivileged
                  (new sun.security.action.GetPropertyAction
                   ("java.awt.graphicsenv", null));

              try {
  //                      long t0 = System.currentTimeMillis();
                  localEnv =
                      (GraphicsEnvironment) Class.forName(nm).newInstance();
  //              long t1 = System.currentTimeMillis();
  //              System.out.println("GE creation took " + (t1-t0)+ "ms.");
                  if (isHeadless()) {
                      localEnv = new HeadlessGraphicsEnvironment(localEnv);
                  }
              } catch (ClassNotFoundException e) {
                  throw new Error("Could not find class: "+nm);
              } catch (InstantiationException e) {
                  throw new Error("Could not instantiate Graphics Environment: "
                                  + nm);
              } catch (IllegalAccessException e) {
                  throw new Error ("Could not access Graphics Environment: "
                                   + nm);
              }
          }

          return localEnv;
      }

That's what gets executed.

And in the original post which you don't seem to have read, I said the code is accessing the property "java.awt.graphicsenv"

If that other project using axis doesn't have the same problem it may be because it may be running in a different tomcat configuration or the axis library allowed the access to that property. But we cannot be sure. That's pure speculation. So why don't you test the following and see what gets printed:

        String nm = (String) java.security.AccessController.doPrivileged
            (new sun.security.action.GetPropertyAction
             ("java.awt.graphicsenv", null));

    System.out.println("java.awt.graphicsenv = " + nm );

It it prints null then you now what the problem is. You don't have that property in your system, or the security forbids you do use it.

It is very hard to tell you from here: "Go and edit file xyz and add : fail = false" So you have to do your work and try to figure out what's the real reason.

Start by researching what's the code being executed is ( which I have just posted ) and follow by understand what it does and how does all that "AccessController.doPrivileged" works. (You may use Google + StackOverflow for that).

这篇关于在Tomcat上访问GraphicsEnvironment.getLocalGraphicsEnvironment时发生NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆