Java package: Difference between revisions

1,490 bytes added ,  11 October 2013
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>
:If you are using a Linux system this would look probably more like:
: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 usually symlinked to from /usr/bin but on Windows that is usually not the case. If the Octave command:
*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. Watch out that 'getenv("PATH")' contains no spaces. Please note that in Windows operating system, already existing presence of Java address in PATH Environment Variable (present in Windows System Properties) can create conflict and prevent the Java package to be installed. Such presence can be spotted using this command:
: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.
:<pre>strsplit (getenv("PATH"), pathsep)</pre>
:Be sure to remove any previous addressing of java installation in PATH environment variable before the setenv command.


===Compile and install the package in Octave===
===Compile and install the package in Octave===
Anonymous user