|
Hi Nick,
/QIBM/UserData/Java400/ext is the Java "extensions" directory. It's
supposed to be used for extensions to the Java language, not for your
own code.
It's not the "default directory of your CLASSPATH" because it's not part
of your CLASSPATH. Indeed, the files in that directory are loaded
before the CLASSPATH is even considered.
One of the biggest problems with using the extensions directory is that
any code in that directory is loaded automatically for every Java
program. That means you can never have two versions (such as test &
production versions) running on the same system, because the stuff in
the ext directory is *always* loaded first.
My recommendation is that you remove it from the ext directory.
Instead, create your own directory. Maybe with something like this:
CRTDIR ('/java')
CRTDIR ('/java/publicclasses')
Put all of your classes you want to be available to everyone into that
directory, and then set the CLASSPATH envvar to point to that directory.
ADDENVVAR ENVVAR(CLASSPATH) VALUE('/java/publicclasses')
That's just a suggestion though. The reason your example doesn't work
is that it's expecting the Difference class to be in a subdirectory
named "levenshtein". So for every directory in yoru CLASSPATH, it's
looking for a subdirectory named levenshtein that contains a Difference
class.
In the above example, if the CLASSPATH is /java/publicclasses then your
code is looking for a file in the IFS named
/java/publicclasses/levenshtein/Difference.class -- because of the way
you coded it, it's looking for a levenshtein/Difference.class in all of
your CLASSPATH directories.
Nick Arndt wrote:
Hi all I have a need to call a java program from RPG. Here is my'levenshtein.Difference':
prototypes:
d Levenshtein pr o extproc(*java:
d
d *constructor)CLASS(*JAVA:'java.lang.String')
d LD pr 10i 0 extproc(*java:
d
'levenshtein.Difference':
d 'LD')
d iString1 like(String1)
d iString2 like(String1)
d Class s o class(*java:
d 'levenshtein.Difference')
d String1 s o
change
/free
// constructor for java class
Class = Levenshtein();
When I try to call the above constructor I get an RNX0301 NoClassDefFound
Here is my java program:
The Program is in a Jar file located in QIBM\UserData\Java400\ext
Is this the default directory for the classpath var or do i have to
it to look here?+
package levenshtein;
public class Difference {
//*****************************
// Compute Levenshtein distance
//*****************************
public int LD (String s, String t) {
int d[][]; // matrix
int n; // length of s
int m; // length of t
int i; // iterates through s
int j; // iterates through t
char s_i; // ith character of s
char t_j; // jth character of t
int cost; // cost
// Step 1
n = s.length ();
m = t.length ();
if (n == 0) {
return m;
}
if (m == 0) {
return n;
}
d = new int[n+1][m+1];
// Step 2
for (i = 0; i <= n; i++) {
d[i][0] = i;
}
for (j = 0; j <= m; j++) {
d[0][j] = j;
}
// Step 3
for (i = 1; i <= n; i++) {
s_i = s.charAt (i - 1);
// Step 4
for (j = 1; j <= m; j++) {
t_j = t.charAt (j - 1);
// Step 5
if (s_i == t_j) {
cost = 0;
}
else {
cost = 1;
}
// Step 6
d[i][j] = Minimum (d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1]
cost);
}
}
// Step 7
return d[n][m];
}
// get minimum of three values
private int Minimum (int a, int b, int c) {
int mi;
mi = a;
if (b < mi) {
mi = b;
}
if (c < mi) {
mi = c;
}
return mi;
}
}
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.