Interactivate


Instructions to Enable Copy/Paste Functionality in Java


Shodor > Interactivate > Instructions to Enable Copy/Paste Functionality in Java

The latest release of the Java Virtual Machine by default disallows the Java Virtual Machine access to the system clipboard. This means that without custom configuration of the Java Virtual Machine, data cannot be copied from a Java applet written in Swing to a different computer application such as Microsoft Excel. The following instructions demonstrate how to configure your Java Virtual Machine to permit access to the system clipboard, allowing data transfer between Swing Java applets and other computer applications such as Microsoft Excel, Microsoft Word, or text editors.

Instructions for Mac Users:

From the Finder, open a terminal by selecting Applications -> Utilities -> Terminal

In the command prompt, type the word "policytool".

This should open the policy tool. Now follow the instructions for policy tool .

Instructions for PC Users:

First, you must know where you installed your Java Runtime Environment (JRE). If you used the default location, it is likely something like this:

C:\Program Files\Java\jre6

Your JRE location may vary depending on which update of Java you have installed on your computer. One possibility is

C:\Program Files\Java\jre1.6.0_06

You may have multiple JRE locations. For this purpose, you can use any one of them.

Within your JRE folder, open the folder called "bin". Run the executable file "policytool" by double clicking the "policytool" icon inside the bin folder.

This should open the policy tool. Now follow the instructions for policy tool .

Instructions for Policy Tool:

You should now have the Policy Tool open.

Note: You may be presented with an error message stating your policy file cannot be found. There is no reason to be alarmed by this. It only means that you are setting your policy file for the first time. Click "OK" to dismiss the error message.

Within the Policy Tool window, select "File -> Save". This will save a new java policy file in your user account on your computer. You will later use the Policy Tool to edit your policy file to grant the Java Virtual Machine access to the system clipboard.

If this is the first time you are saving your policy file, after you select "File -> Save" you will be presented with a window that looks like this:

Click the down arrow to the right of the blank text field. The window expands to look like this:

Navigate to your "home" directory. Your home directory will depend on your computer's configuration. You may be able to click on your username in the left pane under "PLACES". In other cases, you may need to click on your hard drive icon in the left pane under "DEVICES", select Users, and then select your username.

For Windows Vista or Windows 7, this will be located under "Users" on your C drive. For example:

C:\Users\Joe Smith

For Windows XP or Windows 2000, this will be located under "Documents and Settings". For example:

C:\Documents and Settings\Joe Smith

In the "Save As" textbox, type exactly:

.java.policy

Important: Be sure that you are saving the file with a file that begins with a "." (DOT) and matches EXACTLY the name ".java.policy". The preceding DOT signifies it is a system file so it will be read by the Java Virtual Machine. Therefore, it is critical that the preceding "." in the file name exist.

Click the Save button. You may be presented with a warning that filenames beginning with a "." are reserved for system files:

You want your file to be a system file as explained above, so click Use ".".

You should receive a congratulatory message that you successfully saved your new policy file. Click OK. The location of your new policy file should now be in the uneditable text field "Policy File" in the Policy Tool Window.

After you have saved your policy initial file, you need to edit your policy file to grant your Java Virtual Machine access to the system clipboard. You do this through the same "Policy Tool" window.

In the Policy Tool window, click the "Add Policy Entry" button.

In the Policy Entry window that appears, click "Add Permission" button.

From the Permission drop down list, select "AWTPermission".

From the Target Name drop down list, select "accessClipboard".

The Permission window should look similar to this:

Click OK in the Permissions window.

Click Done in the Policy Entry window.

Save your policy file by selecting "File -> Save" from the Policy Tool window. You should see a similar congratulatory message. Click OK.

Select "File -> Exit" from the Policy Tool window to close the policy editor.

Restart your browser.

You should now be able to copy and paste between Java Swing applets and other computer applications such as Microsoft Excel. Please note to use Ctrl-C and Ctrl-V to copy and paste.

If you still cannot copy and paste, try restarting your computer as some computers may require this.


a resource from CSERD, a pathway portal of NSDL NSDL CSERD