JavaRanch Home    
This page:         last edited 30 June 2014         What's Changed?         Edit

How To Copy Environment Variables   

Several of the entries in the HowToAskQuestionsOnJavaRanch FAQ recommend copying and pasting code and configuration settings into the edit screen instead of typing them.

Here are some tips for capturing system information such as environment variables and directory structures in a Windows environment. Most modern Unix shell windows allow copying and pasting so the results from the "ls -R" and "echo" commands are easy to copy.

Copying an environment variable PATH, CLASSPATH, JAVA_HOME, etc..

For Windows (from the command line):

echo %CLASSPATH% > my-classpath.txt
notepad my-classpath.txt

This will open up a text file containing your CLASSPATH environment variable in notepad; where it will be easy to copy to your clipboard.

For Linux (from the terminal):


This will display your CLASSPATH environment variable which you can copy to the clipboard with ctrl-shift-C. If no CLASSPATH has been set, it will display a blank line.

Simply replace CLASSPATH with PATH, JAVA_HOME, etc. to copy those variables.

Copying a directory structure

In this example, we're going to write the entire directory structure of the "ROOT" webapp that ships with Apache Tomcat (assuming that the current working directory is {tomcat install}\webapps):

dir /b /s ROOT > my-directory-structure.txt
notepad my-directory-structure.txt

When pasting the results into the JavaRanch edit screen be sure to UseCodeTags to insure that everything is rendered as plain text with all indenting preserved.

On a Linux terminal there are several possibilities; these were suggested to me by Rob Spoor and Andrew Monkhouse. My preferred choice of these two is tree –d, but I had to install the tree program first.

find -type d

tree -d

Copying a command-line error message

From the Windows® command line, copy the code from the terminal window and paste it on JavaRanch:

- right click the window title bar
- select Edit, then Mark
- drag around the text you want to copy
- press Enter
- paste on JavaRanch (copied with changes from a post by Rob Spoor)

On a Linux terminal, simply highlight the text with the mouse and use ctrl-shift-C.

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton