why met "java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment"?

ArcherHu
ArcherHu used Ask the Experts™
on
why met error message "java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment" when run the problem? how to solve this problem? I didn't want to install X windows.

freebsd4.6 + JDK 1.3.1 + tomcat4.1.12

thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Did you set the classpath when you ran java as well as javac?
Top Expert 2016

Commented:
In fact, did you compile it yourself?

Author

Commented:
sorry, I can compile successfully. I met the problem when I run the problem. some guy told me that I can install X window to solve this problem but I didn't what to install it. is there another way to solve it?
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Top Expert 2016

Commented:
If you can compile it then you shouldn't get the error you mentioned. Can you show me your command lines for:

1. Compiling?
2. Running?

Author

Commented:
compile line:
/usr/local/jdk1.3.1/bin/javac -classpath /usr/local/ja*/common/lib/servlet.jar ImageServlet.java

run:
use browser
Top Expert 2016

Commented:
OK. Do any of the Sun X11 classes appear in any import directives in your code?

Author

Commented:
I found the problem line is
"Graphics g = Image.getGraphics();"

Author

Commented:
I have to go to bed now. hope you can help me to solve my problem! thanks!
Top Expert 2016

Commented:
One or more of your classes (such as the one you mentioned) probably have dependencies among the X11 classes.

1. You may not have these in your library
2. Tomcat may not be finding them

You can test the first situation out by issuing the command:

jar -tvf $JAVA_HOME/jre/lib/rt.jar | grep X11

if there's nothing shown, then you haven't got them.
Commented:
Image.getGraphics() won't work unless you have a graphics environment. You said you don't have XWindows installed, therefore you don't have a graphics environment.
In fact, any graphics operation won't work unless you have a graphics environment - regardless of whether you're actually displaying an image or not.

This is actually a bug that has been fixed in JDK 1.4. You can solve your problem by using JDK 1.4 and adding the following property to the java command line:

-Djava.awt.headless=true

If for some reason you can't switch to 1.4 you'll either have to install XWindows or find a custom graphics package that can do the job you want without using the graphics environment.
There are a few out there since you're not the first one to have run into that problem, but I'd have to know what you want to do with Image and Graphics.
Top Expert 2016

Commented:
I'm a little confused here Konst, as ArcherHu says:

>>
run:
use browser
>>

so he must have *some* kind of graphics environment, unless he's using a test-based browser surely?
Top Expert 2016

Commented:
Sorry that should have been "text-based browser"

Author

Commented:
Konst,
first, I couldn't install JDK1.4 because there were no JDK1.4 from freebsd now.
second, if I can get JDK1.4(for example:I change to use linux),I use the appliction via browser like IE, I couldn't add the option because I wasn't run the program via command line

Commented:
> so he must have *some* kind of graphics environment, unless he's using a test-based browser surely?

You're right of course.
He most probably has some graphics environment on the machine he is using the browser from. But Tomcat might be running on a different machine without a graphics environment. ArcherHu didn't specify that.

Still, I may have jumped to the wrong conclusion. So to be more precise:

If Tomcat is running on a machine without any graphics environment, try my solution. If it's not, make sure you have the necessary classes as CEHJ suggested.

Commented:
Sorry ArcherHu, I missed your last post.

> second, if I can get JDK1.4(for example:I change to use linux),I use the appliction via browser like IE, I couldn't add the option because I wasn't run the program via command line

You can still add the option. Tomcat is starting the virtual machine your program is running in.
Look at the script that is starting Tomcat. Somewhere "java" will be executed with several command line parameters. If my solution applies, you could add the parameter I mentioned there.

Author

Commented:
yes, i run tomcat a freebsd what without X window, just I didn't want to install it. I just use the machine as a web server and mail server.

Author

Commented:
ok, Thanks! maybe i will try both the two ways!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial