java.awt.Color error
Asked Answered
P

4

0

I have this simple Jsp page:

<%@ page language="java" import="java.awt.Color"%> <%
Color background = Color.white;
%>

Which fails with following error:

java.lang.NoClassDefFoundError
    at _text__jsp._jspService(/text.jsp:3)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
    at com.caucho.jsp.Page.subservice(Page.java:506)
    at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
    at com.caucho.server.http.Invocation.service(Invocation.java:315)
    at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
    at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:346)
    at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274)
    at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
    at java.lang.Thread.run(Thread.java:534)

I'm running it on Resin 2.1.13.

Any idea what's causing this?

Plasmosome answered 9/1, 2009 at 9:17 Comment(0)
P
0

Not sure about the issue. I can run your code successfully in my Tomcat. May be this problem is particular to Resin. Or, as said by Dave, may be a headless issue.

Your best bet is to convert the image in some POJO and then spit that to the browser, or may be save it somewhere on the disk and then link it in your JSP. If problem persists, try running in headless mode, as Dave pointed out.

Moreover, its important to understand that JSP is a view technology for the web, and must not do that kind of graphics manipulation.

Pomona answered 9/1, 2009 at 9:48 Comment(3)
Can you give a reference for the info that containers don't allow AWT to be loaded? I seem to recall that a system I once worked on used AWT classes to create an Image which was then converted to a GIF.Gentianaceous
Oops -- I misread the answer a little, you're saying it doesn't allow them in JSPs but it will allow them to be used within normal objects. Still, I would be interested to see a reference for this.Gentianaceous
No there is nothing in the specs. Actually, I can run this code in Tomcat easily, without any issues. It must be something else, may be headless thing like you mentioned. Or may be this problem in specific to Resin. Editing my post accordingly.Pomona
G
1

In the past I've used AWT classes inside servlet containers. The issue that needs to be dealt with is that, on a server system, there is probably no graphics display running that AWT can connect to, which by default causes it to fail.

The solution is to pass a system property that tells AWT it is running on a "headless" system. In general this is done by passing "-Djava.awt.headless=true" to the java command line.

Here's a reference regarding accomplishing this for Resin: http://www.caucho.com/support/resin-interest/0209/0062.html. The OP in that thread also reported a NoClassDefFound error.

Gentianaceous answered 9/1, 2009 at 20:53 Comment(1)
As far as I experienced, for headless thingy, you get some Display Error.Pomona
P
0

Not sure about the issue. I can run your code successfully in my Tomcat. May be this problem is particular to Resin. Or, as said by Dave, may be a headless issue.

Your best bet is to convert the image in some POJO and then spit that to the browser, or may be save it somewhere on the disk and then link it in your JSP. If problem persists, try running in headless mode, as Dave pointed out.

Moreover, its important to understand that JSP is a view technology for the web, and must not do that kind of graphics manipulation.

Pomona answered 9/1, 2009 at 9:48 Comment(3)
Can you give a reference for the info that containers don't allow AWT to be loaded? I seem to recall that a system I once worked on used AWT classes to create an Image which was then converted to a GIF.Gentianaceous
Oops -- I misread the answer a little, you're saying it doesn't allow them in JSPs but it will allow them to be used within normal objects. Still, I would be interested to see a reference for this.Gentianaceous
No there is nothing in the specs. Actually, I can run this code in Tomcat easily, without any issues. It must be something else, may be headless thing like you mentioned. Or may be this problem in specific to Resin. Editing my post accordingly.Pomona
I
0

I had this same issue on Tomcat on Linux. I would get this message intermittently. It was due to maxing out the number of open File Descriptors on the OS.

I'm not sure how Java loads classes as required, but I assume this limit stopped it from loading classes that it needed from the runtime.

I followed these instructions outlined here:

How do I change the number of open files limit in Linux?

Namely:

Setting a hard limit in /etc/security/limits.conf

* hard nofile 64000

Logging out and logging in again, then running:

ulimit -n 64000

in my shell session before starting Tomcat. I added the above command to my .bashrc file to make sure that the limits were set each time I logged on.

Illustrator answered 17/7, 2013 at 7:11 Comment(0)
R
-1

Some VM with the -server option don't load the java.awt. package at all ( nor javax.swing and others )

This is to avoid loading classes that won't be needed.

By the way, the class

java.awt.Color

Won't be any useful in a jsp page. It is used to display colors in java desktop applications.

What are you trying to do? Perhaps there is a better way.

Romulus answered 9/1, 2009 at 9:17 Comment(2)
Oscar, in that case, it should not even possible if we do it in a POJO in the same application. So, do you mean we need another application - in order to achieve this - in another JVM?Pomona
I had to re-read your comment several times until I get it! : - ) You're right!, the -server is used to specify some strategies for the VM to behave. The restriction is impossed by the servlet container it self, as you said. Good point.Romulus

© 2022 - 2024 — McMap. All rights reserved.