Back
Preparing Matlab to use psychWithJava
This section explains how to prepare Matlab for development
with psychWithJava package.
Setup involves two steps: Setting the JVM version and
setting the javaclasspath variable. OS specific instructions
are given in alphabetical order.
Step 1: Set the JVM version
Launch Matlab on your system and check the Java version. Type
and press enter. If the reported Java version is not 1.6 but you prefer to use
1.6 then you will
have to configure your system to make Matlab use version 1.6. This is
explained
here.
I give the current instructions below, but
for most recent instructions you should follow the link above.
(if this setup does not properly work, try using JDK 5.0
instead of JDK 6.0. Some versions of Matlab and JDK 6.0 do not
work together very well.)
Linux
First find out where your JVM is installed.
This is where the run time environment is located.
If you followed my instructions
here, then
the path should be
Next set the MATLAB_JAVA variable.
Open a terminal and type
and press enter. If the response indicates that you are using
bash, type
export MATLAB_JAVA=<path to JVM>
and press enter. If your shell is tcsh, type
setenv MATLAB_JAVA <path to JVM>
and press enter. Then start matlab as usual and check whether
Java version is now 6.0 (1.6).
You may need to start Matlab from the same
terminal as you set the MATLAB_JAVA environment variable. If you
want to add the setting to your start up script so that you
don't have to manually set it everytime you use Matlab you can
put the above commands in your .bash_profile or .tcshrc file.
Next: Goto "Step 2: Set the javaclasspath" below
Mac OS X
MATLAB always uses the default version of the JVM
installed on the computer. By default Mac OS X uses the
older 1.4 version. If you followed the
instructions on the previous page
your preferred version
should be 6.0.
However if you don't want to install the most recent
revision and/or change the system wide
default version from 1.4 to 6.0,
you must specify the JAVA_JVM_VERSION environment variable for
Matlab.
Open a terminal and find
out your SHELL.
More on how to find out your shell is here.
If your shell
is bash, type
export JAVA_JVM_VERSION=1.6
and press enter. If your shell is tcsh type
setenv JAVA_JVM_VERSION 1.6
and press enter. Remember to check that Java version is now
6.0 (1.6)
from within Matlab, to do this start a new Matlab
session. If you
want to add the setting to your start up script so that you
don't have to manually set it everytime you use Matlab you can
put the above commands in your .bash_profile or .tcshrc file.
More on start-up scripts.
On OS X, the bash environment changes do not take effect
in FInder. Therefore if you performed the above steps and
started a new Matlab session by double clicking on the
Matlab icon, the JVM changes you performed will not apply.
To work around this inconvinience you have to start Matlab
using Terminal and typing in the full path to the Matlab
program. If you have set JDK 6.0 as the system wide default
you don't have to worry about this issue.
Next: Goto "Step 2: Set the javaclasspath" below
MS Windows 2000/XP
Open Control Panel
Click System
Choose the Advanced tab and then click the
Environment Variables button.
You now can set (or add) the MATLAB_JAVA system
environment variable to the path of your JVM.
You can use the classes of psychWithJava from any directory
on your system. However, to do so you have
to include the path to your java packages in the
javaclasspath variable. In order to find class definitions,
Matlab searches directories and files that are set in the javaclasspath
variable.
There are two ways of setting the javaclasspath in Matlab.
One is static, other is
dynamic. Static one sets the path permenantly until you
change the settings. That is, you
don't need to set the path every time you launch Matlab.
Dynamic path is temparory and
lives only during the session in which you set it.
Setting the dynamic path
The official instructions are given
here.
I will
sketch the steps below, but I recommend to
follow the above link
for most accurate information.
Launch Matlab.
Add the psychWithJava package into the javaclasspath.
Type
javaaddpath <full_path_to_psychWithJava>
and press enter.
<full_path_to_psychWithJava>
is the full path to the psychWithJava.jar file.
For example /home/boyaci/javaClasses/psychWithJava.jar
on Linux,
or /Users/boyaci/javaClasses/psychWithJava.jar on Mac OS X,
or or C:\XXX\javaClasses\psychWithJava.jar on MS Windows.
Make sure that the path is
added to the classpath. To check the java classpath (in Matlab command window),
type
and press enter. Names of all packages in the current java class
path should be listed including psychWithJava package.
Setting the static path
Search Mathworks' web page for official instructions.
Here I will sketch the steps that worked last time I performed this step.
To make changes in the static path you
have to edit the classpath.txt file.
There may be two
versions of that file: local and shared.
If you edit the shared one it will affect all users
who share the same MATLAB root directory.
Local file can be found/created in your own startup
directory. When MATLAB starts up, it looks for classpath.txt
first in your startup directory,
and then in the default location. It uses the file it finds first.
To see which classpath.txt
file is currently being used by your MATLAB environment,
launch Matlab and type
press enter.
Edit the classpath.txt file either with Matlab editor
or with another editor of your choice on your system.
(On Linux or Mac OS X you may have to have administrative
previliges to edit the shared
classpath.txt file.)
Add the full path to the
psychWithJava.jar file.
For example /home/XXX/javaClasses/psychWithJava.jar
on Linux,
or /Users/XXX/javaClasses/psychWithJava.jar on Mac OS X,
or or C:\XXX\javaClasses\psychWithJava.jar on MS Windows.
Exit from Matlab
and re-launch it.
Make sure that the <path_to_your_java_packages>
is added in the javaclasspath. To check the java classpath (in Matlab command window),
type
and press enter. Names of all packages in the current java class
path should be listed including psychWithJava package.
Back
|