Re: JLink
- To: mathgroup at smc.vnet.net
- Subject: [mg54016] Re: [mg53975] JLink
- From: Todd Gayley <tgayley at wolfram.com>
- Date: Mon, 7 Feb 2005 03:13:15 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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 >SampleProgram.java which is located in the directory > >C:\Program Files\Wolfram >Research\Mathematica\5.1\AddOns\JLink\Examples\Part2 > >1. I am using NetBeans 3.6 as an IDE and, after setting the working >directory to > C:\Program Files\Wolfram >Research\Mathematica\5.1\AddOns\JLink\Examples\Part2, >and the classpath to > C:\Program Files\Wolfram > Research\Mathematica\5.1\AddOns\JLink\JLink.jar > >SampleProgram.java will compile and execute correctly. > >2. If I now move the SampleProgram.java 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(ClassLoader.java:537) > at >java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) > at java.net.URLClassLoader.defineClass(URLClassLoader.java:251) > at java.net.URLClassLoader.access$100(URLClassLoader.java:55) > at java.net.URLClassLoader$1.run(URLClassLoader.java:194) > at java.security.AccessController.doPrivileged(Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:187) > at java.lang.ClassLoader.loadClass(ClassLoader.java:289) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) > at java.lang.ClassLoader.loadClass(ClassLoader.java:235) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) >Exception in thread "main" > >It appears that these exceptions are the result of an inability to find the >file > >"C:\Program Files\Wolfram >Research\Mathematica\5.1\AddOns\JLink\SystemFiles\Libraries\Windows\JLinkNat >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 >JLinkNativeLibrary.dll? Skip, 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. -or- 2) Create a new NetBeans project whose root is at AOL12_SRC/JLink_Examples/Part2/ instead of just AOL12_SRC. -or- 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 SampleProgram.java file and recompiling: 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