MathGroup Archive 2005

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

Search the Archive

JLink /[] - ClassNotFoundException

  • To: mathgroup at
  • Subject: [mg57608] JLink /[] - ClassNotFoundException
  • From: Felix Kossak <felix.kossak at>
  • Date: Thu, 2 Jun 2005 05:16:46 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


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:

    CommandLine -> "C:\\Program Files\\Java\\j2re1.4.2\\bin\\java.exe
    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[
oos = JavaNew[ "", os ];
oos@writeObject[ algorithm ];

This, however, fails:

fis = JavaNew[
ois = JavaNew[ "", fis ];

algin = ois@readObject[]

It produces the following error messages:

Java::excptn: A Java exception occurred: java.lang.ClassNotFoundException: \
	at$ Source)
	at Method)
	at 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 Source)
	at Source)
	at Source)
	at Source)
	at Source)
	at Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source).


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,

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