2

I have a Java application that has a line of code that says:

String myString="Some Text";
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(myString, null);

And this works great when I run my application in Eclipse with Java 5. When I create a .ear file and deploy it on websphere i get an exception that looks like this:

Caused by: java.awt.HeadlessException
      at sun.awt.HeadlessToolkit.getSystemClipboard(HeadlessToolkit.java:306)
      at something.something.something.package$MyButtonListener.buttonClick(View.java:271)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:618)
      at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:512)

I can't seem to solve this, does anyone have any ideas? I understand that it is trying to set the clipboard on the server but how do I set it on the user of the webapplications computer?

why_vincent
  • 2,172
  • 9
  • 33
  • 49

2 Answers2

3

Your WebSphere environment does not have a monitor-based GUI ("head").

What is your intention in setting the clipboard on a server?

EDIT: All the Toolkit methods apply to the computer running the Java code. If you want to manipulate the client, you need to deploy client-side code. See Set clipboard content in any browser.

Community
  • 1
  • 1
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • I would like to set the clipboard on the computer that is accessing the webapplication, not the server. But maybe that is impossible? – why_vincent Nov 22 '11 at 08:15
1

You can only use the AWT method when you are running a gui-application on the client.

For a server-side application you don't have that gui, because you are just rendering pages. The server is actually running headless(no screen attached) so you get a HeadLessException.

You need to render some javascript or flash in your pages that cause the copying to clipboard: How to Copy to Clipboard in JavaScript?

Community
  • 1
  • 1
Udo Held
  • 12,314
  • 11
  • 67
  • 93