Java package: Difference between revisions
→Make sure that the build environment is configured properly
Line 108: | Line 108: | ||
*Note that JDK is not equal to JRE (Java Runtime Environment). The JDK home directory contains subdirectories with include, library and executable files which are required to compile the java package. These files are not part of the JRE, so you definitely need the JDK. | *Note that JDK is not equal to JRE (Java Runtime Environment). The JDK home directory contains subdirectories with include, library and executable files which are required to compile the java package. These files are not part of the JRE, so you definitely need the JDK. | ||
*Do not use backslashes but ordinary slashes in the path. Set the environment variable {{Codeline|JAVA_HOME}} according to your local JDK installation. Please adapt the path in the following examples according to the JDK installation on your system. If you are using a Windows system that might be: | *Do not use backslashes but ordinary slashes in the path. Set the environment variable {{Codeline|JAVA_HOME}} according to your local JDK installation. Please adapt the path in the following examples according to the JDK installation on your system. If you are using a Windows system that might be: | ||
:<pre>octave> setenv ("JAVA_HOME", "C:/Java/jdk1.6.0_33");</pre> | :<pre>octave> setenv ("JAVA_HOME", "C:/Program Files/Java/jdk1.6.0_33");</pre> | ||
: | :On Linux systems the location of the Java JDK varies from distro to distro. It could look like: | ||
:<pre>octave> setenv ("JAVA_HOME", "/usr/local/jdk1.6.0_33");</pre> | :<pre>octave> setenv ("JAVA_HOME", "/usr/local/jdk1.6.0_33");</pre> | ||
:or maybe something like (on e.g., Mageia, Fedora and Ubuntu): | |||
:<pre>octave> setenv ("JAVA_HOME", "/usr/lib/jvm/java-1.7.0-openjdk.i386");</pre> | |||
:If you are on Linux and can't find out what JAVA_HOME should look like, the following trick may help. | |||
:Start a shell and issue the command: | |||
: which javac | |||
:Usually this gives you a symlink, indicated by a "->", e.g., | |||
: lrwxrwxrwx 1 root root 21 Apr 28 21:00 /usr/bin/javac -> /etc/alternatives/javac* | |||
:Now just follow the targets (to the right of the "->") until you arrive at the real file: | |||
: ls -l /etc/alternatives/javac | |||
: lrwxrwxrwx 1 root root 44 Jul 17 23:41 /etc/alternatives/javac -> /usr/lib/jvm/java-1.7.0-openjdk.i386/bin/jar* | |||
: ls -l /usr/lib/jvm/java-1.7.0-openjdk.i386/bin/jar* | |||
: -rwxr-xr-x 1 root root 3832 Jun 23 03:11 /usr/lib/jvm/java-1.7.0-openjdk.i386/bin/javac* | |||
:(The "real file doesn't have "l" file attribute and is probably only writable by root.) | |||
:Once you get there, JAVA_HOME should be set to the full path of the executable excluding the "/bin/javac" part (i.e., "/usr/lib/jvm/java-1.7.0-openjdk.i386"). | |||
:Note, that on all systems you must use the forward slash {{Codeline|/}} as the separator, not the backslash {{Codeline|\}}. If on a Windows system the environment variable {{Codeline|JAVA_HOME}} is already defined using the backslash, you can easily change this by issuing the following Octave command before starting the installation: | :Note, that on all systems you must use the forward slash {{Codeline|/}} as the separator, not the backslash {{Codeline|\}}. If on a Windows system the environment variable {{Codeline|JAVA_HOME}} is already defined using the backslash, you can easily change this by issuing the following Octave command before starting the installation: | ||
:<pre>octave> setenv ("JAVA_HOME", strrep (getenv ("JAVA_HOME"), '\', '/'))</pre> | :<pre>octave> setenv ("JAVA_HOME", strrep (getenv ("JAVA_HOME"), '\', '/'))</pre> | ||
*The Java executables (especially the Java compiler, javac) should be in the PATH. On Linux they're | *The Java executables (especially the Java compiler, javac or javac.exe, and the Java archiver, jar or jar.exe) should be in the PATH. On Linux they're often symlinked to from /usr/bin (see above) but on Windows that is usually not the case. To that end, during installation of the Java package version 1.2.9+ a file "preinstall.m" is run; preinstall.m takes care of required settings, provided the JAVA_HOME environment variable has been set properly. | ||
:If you insist on manually adding the Java executables path to the Windows PATH, do as follows: | |||
:Check if by any chance the executables are in the PATH by issuing the Octave command: | |||
:<pre>octave> system ('javac -version 2> nul')</pre> | :<pre>octave> system ('javac -version 2> nul')</pre> | ||
:doesn't return zero (i.e., the command "javac -version" doesn't return normally), the command: | :If this returns zero you're OK. If it doesn't return zero (i.e., the command "javac -version" doesn't return normally), the command: | ||
:<pre>octave> setenv ("PATH", [ getenv("JAVA_HOME"), filesep, "bin", pathsep, getenv("PATH") ])</pre> | :<pre>octave> setenv ("PATH", [ getenv("JAVA_HOME"), filesep, "bin", pathsep, getenv("PATH") ])</pre> | ||
:should do the trick | :should do the trick (watch out that 'getenv("PATH")' contains no spaces). Better don't fiddle with the Windows PATH through the Control Panel etc. The above procedure (the same that preinstall.m invokes) only adapts the PATH for the current Octave session and ensures that the Java executables you need are first in the PATH, before any others on your system. Again: provided you've setup JAVA_HOME correctly. | ||
: | |||
===Compile and install the package in Octave=== | ===Compile and install the package in Octave=== |