Copy And Paste in Java Applets

For a while now, I've noticed that copy and paste no longer works in the Admin Applets in UCM.  This was a minor annoyance as I was typically just trying to copy and paste a content ID or line of scripting.  But it suddenly became a real problem for me when I needed to create an option list of countries.  I had the list nicely formatted in my Notepad++, but no way to copy and paste it into my option list dialog.

Well, it turns out with the release of the Java Plug-in 1.6.0_24 in February 2011, copy and paste from the system clipboard was deemed a security hole and disabled.  You can copy and paste BETWEEN applets.  But if you try to use something from your main clipboard, it can't be copied in.  

So there are a couple of options for a workaround.  You can roll back to an earlier version of the plug-in.  That will work, but chances are all future releases will still keep copy and paste disabled, so you'd never be able to upgrade.  

The other alternative is to provide a custom java security policy file which enables access to the system clipboard again.  

  1. First locate your local Java Security Policy file.  The file is named java.policy and should be in the lib\security folder of your Java installation.  On Windows 7, it can be found at C:\Program Files (x86)\Java\jre6\lib\security.
  2. Copy this file to your home folder (ex. C:\Users\Kyle).
  3. Rename the file to .java.policy (note the period at the beginning). 
  4. Edit the file in a text editor.  Locate the line of text
    // "standard" properies that can be read by anyone

  5. Add the following line just below this line.
    // "standard" properies that can be read by anyone
    permission java.awt.AWTPermission "accessClipboard";

  6. Save the file.
  7. Close any open browsers and ensure that Java is not running before testing.

 

 While you can modify the java.policy file directly in the lib/security folder, chances are it will get overwritten again on the next JRE update.  This method should allow those changes to persist.

Comments:

On Windows XP/Server 2003, Windows Explorer will not let you create a file that starts with a period. http://blogs.msdn.com/b/oldnewthing/archive/2008/04/14/8389268.aspx

Instead, you can open java.policy with your favorite text editor (Notepad++) and use that to save the file (starting with a period) to your home directory. You can also use the command line to accomplish the same thing.

Posted by Jonathan Hult on July 20, 2011 at 02:44 AM CDT #

Interesting! I noticed this a couple of times and just thought I was losing my mind or it was something related to VMWare. Nice catch Kyle!

Posted by Omid on July 24, 2011 at 09:33 AM CDT #

Very Helpful!

Posted by anix on August 03, 2011 at 01:08 PM CDT #

Fantastic :) Very helpful indeed. Thanks Kyle.

Posted by thrax on August 24, 2011 at 02:31 PM CDT #

Kyle. It is cool. Worked like magic. Thanks mate

Posted by guest on December 28, 2011 at 07:27 PM CST #

hi Kyle,
sorry, what did you mean by "period"? in step 3

3. Rename the file to .java.policy (note the period at the beginning).

Thanks,

Posted by Made on January 04, 2012 at 12:09 AM CST #

Hey Made,

I was referring to the period, or dot, at the beginning of the file name. If I was to call them out, it is: (dot)java(dot)policy

So the file name should be:

.java.policy

Thanks,
-Kyle

Posted by guest on January 04, 2012 at 07:25 AM CST #

I've been using this configuration but now when i copy table information it gets pasted as a single line instead of dividing by columns. Any idea on why would this be?

Thanks.

Posted by Carlos O on January 10, 2012 at 10:44 AM CST #

Thanks for this write, we knew there was an issue but dont know how to fix. :)

Posted by Peru on February 22, 2012 at 04:11 PM CST #

Thanks so much for this solution.

Posted by Lee on May 03, 2012 at 02:44 PM CDT #

Hello Kyle,
I wonder what would be the future of those applets? They do not allow scripting and because of this, it becomes a nightmare to do simple things.
E.g. I need to add 10 fields into a rule, I have to click severals clicks X 10 to accomplish this. I guess this should change.

Posted by guest on May 09, 2012 at 12:29 PM CDT #

Osom!!

I was about to delete all my files 'cause of this problem. Thank you so much Kyle, it worked 100% =D

Posted by guest on July 25, 2012 at 05:05 AM CDT #

Worked like a charm, thanks!

Posted by guest on August 16, 2012 at 11:32 AM CDT #

I'm trying this solution on computers using JRE 1.6.0_29, and I'm not having much success. Is there more that has to be done for versions newer than _26, or is it more likely that I'm just doing something wrong and need to figure out what? My customers can cut and paste within the application still, but cannot copy from an application to Word and then back into the application.

Posted by Jeff on August 17, 2012 at 10:54 AM CDT #

Hi Kyle

I wonder if you can help with this issue when trying to print via webcenter.

This is the error i get on windows 7 with the lastest java.
Error:
Printing failed
java.lang.SecurityException: check PrintJobAccess

Posted by guest on September 24, 2012 at 10:09 AM CDT #

Hi Kyle,

Thankyou very much for this post. I have been having an enormous amount of problems with this issue.

I'm disappointed to report that your solution did not work for me. I followed the steps exactly twice, and also rebooted the machine.

The only difference I can see is that the file was located in in jre7 not jre6.

Are there any other options I can try? Most of the time I cannot paste anything at all copied from a java application (such as oppenoffice) to another application. Sometimes it will paste after a combination of Ctrl V and edit>paste from the menu.

It is a very annoying problem! Any help would be much appreciated!

Posted by Paul on November 15, 2012 at 10:05 PM CST #

Kyle,
Window 7, JRE 1.6.0_22 java.policy contains the below line for the codebase:
permission java.awt.AWTPermission "accessClipboard";

On some computers, it does not work to copy from Applet into another application such as MS outlook

Any clue

Regards,
Alan M

Posted by guest on December 18, 2012 at 01:43 AM CST #

Hello Alan,

I'm not sure why it would work for some and not others. You may want to check this other post which has a lot of commented on what worked for them: http://www.sqlinform.com/forum4/read.php?3,467

Thanks,
-Kyle

Posted by Kyle Hatlestad on December 18, 2012 at 09:55 AM CST #

Thank you, it just worked. Made it so much easier to copy values into new installation.

Windows 8 x86_64, jdk1.7.0

Posted by guest on February 12, 2013 at 10:21 AM CST #

OK so how do you do this in Linux...

Posted by Richard Baxter on May 17, 2013 at 09:28 PM CDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Kyle Hatlestad is a Solution Architect in the WebCenter Architecture group (A-Team) who works with WebCenter Content and other products in the WebCenter & Fusion Middleware portfolios. The WebCenter A-Team blog can be found at: https://blogs.oracle.com/ ateam_webcenter/

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today