A friend of mine recently started a Java programming class. In the classes, they use Windows and TextPad, so my friend asked me if I could help him set up a similar environment on his Linux box (Ubuntu 12.04) under WINE. Never being one to refuse to help a friend, I agreed.
The following instructions, though, apply just as well to Windows users. Just ignore the references to WINE and issue the commands directly. You may also find that you will not have to alter the Windows PATH variable, because it will be done for you during installation. If you do have to alter it, though, don’t use regedit. Do it the normal way, via My Computer or whatever Microsoft call it on your Windows version.
The first thing to do is to download the latest versions of the installation programs for the Windows version of the Oracle JDK (or a suitable alternative) and TextPad. The links go to the downloads for JDK 7 (32 bit) and TextPad 6. These are the latest versions at the time of writing.
I assume you have WINE installed. If not, simply grab it from your package manager (Synaptic, YaST, etc).
The Oracle JDK download file is a Windows executable, which you run in the normal way under WINE. Change directory to the location of the installation file you downloaded and then execute:
peter@peredur:~$ wine jdk-7u11-windows-i586.exe
The file name above is correct for JDK 7 (32 bit) at the time of writing. The file name may have changed by the time you read this, or if you have the 64 bit version. Just substitute (in place of jdk-7u11-windows-i586.exe) the name of the installation executable that you downloaded.
Accept all the defaults during the installation.
The TextPad download is a zip archive containing a file called setup.exe, so navigate to the location of the zip file and unzip it to somewhere convenient. I unzipped it to a directory off my downloads directory called, unimaginatively, ‘textpad‘.
Navigate to the location of the unzipped setup executable and then run it by executing:
peter@peredur:~$ wine setup.exe
Once again, you should just follow the defaults during installation.
Setting the Windows PATH environment variable
TextPad simple calls javac.exe and java.exe when it compiles and runs Java files you are working on. Therefore you need to make sure that the JDK’s bin folder is included in your Windows path under WINE. To do this you have to use regedit unfortunately. So execute:
peter@peredur:~$ wine regedit
You should now see the regedit window:
Select HKEY_CURRENT_USER/Environment in the tree view in the left hand panel.
Now, assuming that you can’t see a value for “Path” (case insensitive, remember), right-click on the right-hand panel and select New > Value. The new value should be called “Path“. If a value for “Path” (or “PATH” or “path” or whatever) already exists, you will just need to modify its data. Remember that Windows path entries are separated by semi-colons.
Assuming you’re adding a new Path value, simply right click on the “Path” value and select “Modify“. In the dialog box that appears, enter the path to your JDK’s bin folder:
If you accepted all the defaults when you installed the JDK, your path will be the same as mine. Click on “Accept” and that’s it.
You can check that the PATH environment variable has been set correctly by opening the WINE command terminal from a Linux terminal, and echoing it using the command:
peter@peredur:~$ wine cmd Z:\home\peter> echo %path%
You should see the path to the JDK bin folder on the path.
Run TextPad under WINE, from the WINE menu, or however it’s done in your distribution. Under Ubuntu using Unity, you can find it in the Launcher. Alternatively, you coud add the textpad executable to the Windows PATH (remember that entries are separated by semi-colons) and then you will be able to run it from a command prompt:
peter@peredur:~$ wine textpad
The first thing to do after you have TextPad up and running is to check that the Java Tools are installed. Open the Preferences dialog from the TextPad main menu by selecting Configuration > Preferences and then select “Tools” in the tree view in the left hand panel.
There should be three entries under Tools, namely:
- Compile a Java Application
- Run a Java Application
- Run a Java Applet
If these entries are absent, click on the “Add” button and select them from the menu. They will then be added to the tree view.
Now select the “Compile Java” entry in the tree view and examine the parameters in the text box in the main panel. By default, you will see that TextPad has simply “$File” in that position. This means that to compile a Java file, TextPad will use the command:
(where <file> represents the file you are compiling)
This is fine if you are compiling a file that is in the <Default> package. However, you should avoid doing that if you can. Packages allow you to create namespaces specific to you and your applications. Without them you run the risk of name clashes. So, for example, if I have written a Hello World program (who hasn’t), then I would include as the first line in the file, a package declaration something like:
My HelloWorld class will now be in that package and will not clash with all the other HelloWorld classes I have all over the place!
Unfortunately, though, although TextPad will compile this file well enough (Tools > External Tools > Compile Java), when I try to run it, it will fail because the HelloWorld.class file needs to be in folder:
If this folder structure is absent, Java will simply report that it cannot find the class.
So we need to make a small adjustment to our TextPad configuration. Go back to Configuration > Preferences and select Tools > Compile Java.
In the Parameters text box, alter ‘$File‘ to:
-d . $File
The effect of this is to pass the ‘-d‘ option to javac, specifying the current directory (i.e. the one that contains the .java source file, represented by the full stop (.) in the parameters string). When this is done, the compiler (javac) looks to see if there is a package declaration in the source and, if there is, it creates the necessary directories.
Now you can compile your Java file as before (Tools > External Tools > Compile Java) and you will see, if you examine your project’s file system, that the necessary folders have been created and that the .class file is in the correct place.
You will now be able to run your application (Tools > External Tools > Execute Java Application) without errors.