MathGroup Archive 2005

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

Search the Archive

Re: JLink

  • To: mathgroup at
  • Subject: [mg54016] Re: [mg53975] JLink
  • From: Todd Gayley <tgayley at>
  • Date: Mon, 7 Feb 2005 03:13:15 -0500 (EST)
  • Sender: owner-wri-mathgroup at

At 02:17 AM 2/5/2005, D.D. \"Skip\" Snyder wrote:
>I'm trying to exploit the capabilities of JLink to write Java code that uses
>mathkernel.exe as a server.  I am testing the example program
> which is located in the directory
>C:\Program Files\Wolfram
>1.  I am using NetBeans 3.6 as an IDE and, after setting the working
>directory to
>         C:\Program Files\Wolfram
>and the classpath to
>         C:\Program Files\Wolfram 
> Research\Mathematica\5.1\AddOns\JLink\JLink.jar
> will compile and execute correctly.
>2.  If I now move the to another directory say
>         E:\AOL12_SRC\JLink_Examples\Part2
>and change the working directory to accommodate that change, I can compile
>OK but when I try to execute I get the following exceptions:
>java.lang.NoClassDefFoundError: JLink_Examples/Part2/SampleProgram (wrong
>name: SampleProgram)
>         at java.lang.ClassLoader.defineClass0(Native Method)
>         at java.lang.ClassLoader.defineClass(
>         at
>         at
>         at$100(
>         at$
>         at Method)
>         at
>         at java.lang.ClassLoader.loadClass(
>         at sun.misc.Launcher$AppClassLoader.loadClass(
>         at java.lang.ClassLoader.loadClass(
>         at java.lang.ClassLoader.loadClassInternal(
>Exception in thread "main"
>It appears that these exceptions are the result of an inability to find the
>"C:\Program Files\Wolfram
>iveLibrary.dll" which resides in its original installation directory.
>I have tried to register the dll with no luck.  (I get a regsvr32 error
>saying that it cannot find an entry point.)  I have also tried copying
>JLinkNativeLibrary.dll into the new working directory, again with no luck.
>Can anyone educate me on the finepoints of maintaining connections with


Your project's home directory (as determined by NetBeans) is apparently 
AOL12_SRC, and when NetBeans tries to launch the main class it is using the 
class name JLink_Examples/Part2/SampleProgram. The Java runtime then 
expects to load the class file and find that it defines a class named 
JLink_Examples.Part2.SampleProgram, but the class is named simply 
SampleProgram and thus you get an error. You will see a similar error if 
you just cd to the AOL12_SRC directory and execute the command line:

     E:\AOL12_SRC>  java JLink_Examples/Part2/SampleProgram

The name you give to 'java' must be the actual name of the main class. It 
cannot be a relative path to the class file unless the path mirrors the 
package name of the class.

This problem, then, has to do with how your NetBeans project is structured. 
You say that you changed the working directory to accommodate the change in 
location of the class file, but you must have done this incorrectly. I 
don't know much about NetBeans, but you can do one of the following things:

1) Convince NetBeans that the name of the main class is SampleProgram and 
not JLink_Examples.Part2.SampleProgram. This might involve nothing more 
than setting the working directory correctly.


2) Create a new NetBeans project whose root is at 
AOL12_SRC/JLink_Examples/Part2/ instead of just AOL12_SRC.


3) Change the name of the SampleProgram class to 
JLink_Examples.Part2.SampleProgram so that its class name mirrors its 
hierarchical location in the NetBeans project. You would do this by putting 
the following line at the beginning of the file and 

     package JLink_Examples.Part2;

Also note that this has nothing whatsoever to do with 
JLinkNativeLibrary.dll. You should leave that file where it lives in the 
J/Link directory layout.

Todd Gayley
Wolfram Research

  • Prev by Date: Re: Re: New Web Site for Mathematica Users using WikiMedia
  • Next by Date: how to print the complete documentation of an application?
  • Previous by thread: JLink
  • Next by thread: Calling functions in a DLL in Win32