1

I am using Octave 4.0.1 (GUI version) on Windows 7 and am trying to talk to a DDE server. I am using the same approach as the answer to this question Matlab and JDDE. Here's what I have done so far:

  1. Downloaded and unzipped the JDDE package into C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3
  2. Created the files javaclasspath.txt and javalibrarypath.txt in my `prefdir.
  3. Added C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3\pretty-tools-JDDE-2.0.3.jar to javaclasspath.txt.
  4. Added C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3 to javalibrarypath.txt

In addition, I have also run the following command:

javaaddpath('C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3')

I have restarted Octave and tried the following:

>> javaaddpath('C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3\pretty-tools-JDDE-2.0.3.jar')
>> javaclasspath
   STATIC JAVA PATH

      C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3\pretty-tools-JDDE-2.0.3.jar

   DYNAMIC JAVA PATH

      C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3\pretty-tools-JDDE-2.0.3.jar

>>  a = javaObject('com.pretty_tools.dde.client.DDEClientConversation')

error: [java] java.lang.UnsatisfiedLinkError: no JavaDDE in java.library.path
>>  a = javaObject('com.pretty_tools.dde.client.DDEClientConversation')

error: [java] java.lang.NoClassDefFoundError: Could not initialize class com.pretty_tools.dde.client.DDEClientConversation

The description of the java class can be found here.

What am I doing wrong? Is the error message ralated to the java class/package or is there a more fundamental problem? Is there a better to interface to a DDE server from Octave? I should add that, although I am proficient with MATLAB/Octave, I know nothing about java or DDE.

Community
  • 1
  • 1
am304
  • 13,758
  • 2
  • 22
  • 40
  • You are calling `javaObject` incorrectly, the name of the class does not include `()`. – carandraug Jun 08 '16 at 14:48
  • @carandraug Thanks for the comment, am now getting a different error message, will update the question accordingly. – am304 Jun 08 '16 at 15:19
  • I managed to fix it by adding `C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3` to my PATH environment variable. I think the java class couldn't find the DLL even though they were in the same directory because that directory wasn't on the PATH. – am304 Jun 09 '16 at 10:45

1 Answers1

1

Well, after much searching on the internet, I have managed to solve the problem so I'll answer my own question.

The java error message Could not initialize class... seems to generally indicate that either the JAR isn't in the class path (which I know isn't the case here) or that the class definition can't be found even though it existed at compile time (see for example "NoClassDefFoundError: Could not initialize class" error).

Looking in the directory of the JAR class, I saw that there were also two DLL files as part of the package, so I started getting a hunch that somehow the java class as defined in the JAR file couldn't find the DLL files even though they were in the same directory.

In MATLAB, there is something called librarypath.txt where we can reference the directories containing the necessary DLLs (see for example this question). It would seem that there is no such option in Octave (at least none that I could find).

So (and here comes the solution), I tried adding the directory with the JAR & DLL files (C:\Octave\Octave-4.0.1\pretty-tools-JDDE-2.0.3\) to the PATH environment variable in Windows et voila! Suddenly, I was able to run the code without any errors!

Note: for those of you who are newbies to java like me, there is no need to add the directory to the dynamic java path using javaaddpath since it is already present in the static java path via javaclasspath.txt. The difference is that the static path gets loaded by default every time Octave is started, whereas javaaddpath only adds directories to the path temporarily (e.g. when it's needed only by one script or function). See How to make Java classes available to Octave for a better and more detailed explanation.

Community
  • 1
  • 1
am304
  • 13,758
  • 2
  • 22
  • 40