File: How-to-make-Java-classes-available_003f.html

package info (click to toggle)
octave 3.8.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,396 kB
  • ctags: 45,547
  • sloc: cpp: 293,356; ansic: 42,041; fortran: 23,669; sh: 13,629; objc: 7,890; yacc: 7,093; lex: 3,442; java: 2,125; makefile: 1,589; perl: 1,009; awk: 974; xml: 34
file content (173 lines) | stat: -rw-r--r-- 9,026 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: How to make Java classes available?</title>

<meta name="description" content="GNU Octave: How to make Java classes available?">
<meta name="keywords" content="GNU Octave: How to make Java classes available?">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="FAQ-_002d-Frequently-asked-Questions.html#FAQ-_002d-Frequently-asked-Questions" rel="up" title="FAQ - Frequently asked Questions">
<link href="How-to-create-an-instance-of-a-Java-class_003f.html#How-to-create-an-instance-of-a-Java-class_003f" rel="next" title="How to create an instance of a Java class?">
<link href="How-to-distinguish-between-Octave-and-Matlab_003f.html#How-to-distinguish-between-Octave-and-Matlab_003f" rel="prev" title="How to distinguish between Octave and Matlab?">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="How-to-make-Java-classes-available_003f"></a>
<div class="header">
<p>
Next: <a href="How-to-create-an-instance-of-a-Java-class_003f.html#How-to-create-an-instance-of-a-Java-class_003f" accesskey="n" rel="next">How to create an instance of a Java class?</a>, Previous: <a href="How-to-distinguish-between-Octave-and-Matlab_003f.html#How-to-distinguish-between-Octave-and-Matlab_003f" accesskey="p" rel="prev">How to distinguish between Octave and Matlab?</a>, Up: <a href="FAQ-_002d-Frequently-asked-Questions.html#FAQ-_002d-Frequently-asked-Questions" accesskey="u" rel="up">FAQ - Frequently asked Questions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="How-to-make-Java-classes-available-to-Octave_003f"></a>
<h4 class="subsection">37.3.2 How to make Java classes available to Octave?</h4>
<a name="index-classpath_002c-setting"></a>
<a name="index-classpath_002c-difference-between-static-and-dynamic"></a>
<a name="index-static-classpath-1"></a>
<a name="index-dynamic-classpath-1"></a>
<a name="index-javaclasspath_002etxt"></a>
<a name="index-classpath_002etxt"></a>
<a name="index-classes_002c-making-available-to-Octave"></a>

<p>Java finds classes by searching a <var>classpath</var>.  This is a list of Java
archive files and/or directories containing class files.  In Octave
the <var>classpath</var> is composed of two parts:
</p>
<ul>
<li> the <var>static classpath</var> is initialized once at startup of the JVM, and

</li><li> the <var>dynamic classpath</var> which can be modified at runtime.
</li></ul>

<p>Octave searches the <var>static classpath</var> first, then the <var>dynamic
classpath</var>.  Classes appearing in the <var>static</var> as well as in the
<var>dynamic classpath</var> will therefore be found in the <var>static classpath</var>
and loaded from this location.  Classes which will be used frequently or must
be available to all users should be added to the <var>static classpath</var>.  The
<var>static classpath</var> is populated once from the contents of a plain text file
named <samp>javaclasspath.txt</samp> (or <samp>classpath.txt</samp> historically) when the
Java Virtual Machine starts.  This file contains one line for each individual
classpath to be added to the <var>static classpath</var>.  These lines can identify
single class files, directories containing class files, or Java archives with
complete class file hierarchies.  Comment lines starting with a &lsquo;<samp>#</samp>&rsquo; or a
&lsquo;<samp>%</samp>&rsquo; character are ignored.
</p>
<p>The search rules for the file <samp>javaclasspath.txt</samp>
(or <samp>classpath.txt</samp>) are:
</p>
<ul>
<li> First, Octave tries to locate it in the current directory (where Octave
was started from).  If such a file is found, it is read and defines the initial
<var>static classpath</var>.  Thus, it is possible to define a static classpath on a
&rsquo;per Octave invocation&rsquo; basis.

</li><li> Next, Octave searches in the user&rsquo;s home directory.  If a file
<samp>javaclasspath.txt</samp> exists here, its contents are appended to the static
classpath (if any).  Thus, it is possible to build an initial static classpath
on a &rsquo;per user&rsquo; basis.

</li><li> Finally, Octave looks for a next occurrence of file
<samp>javaclasspath.txt</samp> in the m-files directory where Octave Java functions 
live.  This is where <samp>javaclasspath.m</samp> resides, usually something like
<samp><code><span class="nolinebreak">OCTAVE_HOME</span></code><!-- /@w -->/share/octave/<code><span class="nolinebreak">OCTAVE_VERSION</span></code><!-- /@w -->/m/java/</samp>.  You can
find this directory by executing the command

<div class="example">
<pre class="example">which javaclasspath
</pre></div>

<p>If this file exists here, its contents are also appended to the static
classpath.  Note that the archives and class directories defined in this last
step will affect all users.
</p></li></ul>

<p>Classes which are used only by a specific script should be placed in the
<var>dynamic classpath</var>.  This portion of the classpath can be modified at
runtime using the <code>javaaddpath</code> and <code>javarmpath</code> functions.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">octave&gt; base_path = &quot;C:/Octave/java_files&quot;;

octave&gt; % add two JARchives to the dynamic classpath
octave&gt; javaaddpath ([base_path, &quot;/someclasses.jar&quot;]);
octave&gt; javaaddpath ([base_path, &quot;/moreclasses.jar&quot;]);

octave&gt; % check the dynamic classpath
octave&gt; p = javaclasspath;
octave&gt; disp (p{1});
C:/Octave/java_files/someclasses.jar
octave&gt; disp (p{2});
C:/Octave/java_files/moreclasses.jar

octave&gt; % remove the first element from the classpath
octave&gt; javarmpath ([base_path, &quot;/someclasses.jar&quot;]);
octave&gt; p = javaclasspath;
octave&gt; disp (p{1});
C:/Octave/java_files/moreclasses.jar

octave&gt; % provoke an error
octave&gt; disp (p{2});
error: A(I): Index exceeds matrix dimension.
</pre></div>

<p>Another way to add files to the <var>dynamic classpath</var> exclusively for your
user account is to use the file <samp>.octaverc</samp> which is stored in your home
directory.  All Octave commands in this file are executed each time you start a
new instance of Octave.  The following example adds the directory <samp>octave</samp>
to Octave&rsquo;s search path and the archive <samp>myclasses.jar</samp> in this directory
to the Java search path.
</p>
<div class="example">
<pre class="example">% contents of .octaverc:
addpath (&quot;~/octave&quot;);
javaaddpath (&quot;~/octave/myclasses.jar&quot;);
</pre></div>

<hr>
<div class="header">
<p>
Next: <a href="How-to-create-an-instance-of-a-Java-class_003f.html#How-to-create-an-instance-of-a-Java-class_003f" accesskey="n" rel="next">How to create an instance of a Java class?</a>, Previous: <a href="How-to-distinguish-between-Octave-and-Matlab_003f.html#How-to-distinguish-between-Octave-and-Matlab_003f" accesskey="p" rel="prev">How to distinguish between Octave and Matlab?</a>, Up: <a href="FAQ-_002d-Frequently-asked-Questions.html#FAQ-_002d-Frequently-asked-Questions" accesskey="u" rel="up">FAQ - Frequently asked Questions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>