MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

JLink / java.io.ObjectInputStream.redObject[] - ClassNotFoundException

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57608] JLink / java.io.ObjectInputStream.redObject[] - ClassNotFoundException
  • From: Felix Kossak <felix.kossak at scch.at>
  • Date: Thu, 2 Jun 2005 05:16:46 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have a little trouble with reading a Java object from file which I 
have myself serialized before (from the Mathematica environment). It 
works when I write a respective Java class by hand and execute it from 
command line, but the same code does not work within Mathematica - it 
produces a ClassNotFoundException.

Does anyone here have respective experience with serializing / 
deserializing objects using J/Link?

The point seems to be that I use an extra Java library (WEKA), which 
works perfectly for every other code I have tried so far, including 
serializing, just not for deserializing. But it cannot be WEKA's fault 
(as it works in another environment) - the class loader used in J/Link 
seems to be the problem.

Here is some of the context and code:
-------------------------------------

InstallJava[
    CommandLine -> "C:\\Program Files\\Java\\j2re1.4.2\\bin\\java.exe
       -Xmx400m",
    ClassPath -> ".;C:\\Program Files\\Weka\\Weka-3-4\\weka.jar"
];

(Weka 3.4 provides the extra Java library I use)

This, amongst others, works:
----------------------------

algorithm = JavaNew[
    "weka.classifiers.functions.MultilayerPerceptron" ];
algorithm@buildClassifier[ wekaDataSet ];

...

os = JavaNew[
    "java.io.FileOutputStream",
    "C:\\work\\mlf_develop\\WEKA\\algorithm.mod"
];
oos = JavaNew[ "java.io.ObjectOutputStream", os ];
oos@writeObject[ algorithm ];
oos@flush[];
oos@close[];

This, however, fails:
=====================

fis = JavaNew[
    "java.io.FileInputStream",
    "C:\\work\\mlf_develop\\WEKA\\algorithm.mod"
];
ois = JavaNew[ "java.io.ObjectInputStream", fis ];

algin = ois@readObject[]

It produces the following error messages:
-----------------------------------------

Java::excptn: A Java exception occurred: java.lang.ClassNotFoundException: \
weka.classifiers.functions.MultilayerPerceptron
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at java.io.ObjectInputStream.resolveClass(Unknown Source)
	at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
	at java.io.ObjectInputStream.readClassDesc(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source).

$Failed

I also tried to instantiate the variable 'algin' before reading:

algin = JavaNew[ "weka.classifiers.functions.MultilayerPerceptron" ];

but that doesn't help either.


Thanks a lot for any help,
Felix


  • Prev by Date: Re: Complex Oddity
  • Next by Date: Re: FourierTransform
  • Previous by thread: Constrained Optimization
  • Next by thread: Re: JLink / java.io.ObjectInputStream.redObject[] - ClassNotFoundException