Matlab and JDDE - java

Update: The problem was solved with the help of MathWorks. I've published the answer below.
I need to control a program (Zemax) from Matlab. Unfortunately, Zemax only supports DDE for such control, which Matlab does not support any more. It works, but stops working on 64 bit platform after a few (presumable 63) DDE calls.
I wonder if there are working solutions. I could probably program a DLL with correct DDE support and then use DDE in Matlab via this DLL. This is a major effort for me. A more suitable solution would be to use Java DDE methods. Following another post here, I've discovered the JDDE library. However I cannot make it work: Even if I am in the directory with the DLL and JAR files, executing
import pretty-tools.JDDE-2.0.3.*
works fine but calling
a = com.pretty_tools.dde.client.DDEClientConversation()
afterwards (as done here) results in
Undefined variable "com" or class "com.pretty_tools.dde.client.DDEClientConversation".
I have very limited writing privileges on my PC, so I have added the javaclasspath.txt file with the jar/dll location to the directory indicated by prefdir. The file looks like this:
C:\Users\xxxxxxxx\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
Calling javaclasspath shows a long listing with the last lines being:
...
C:\Program Files\MATLAB\R2012b\java\jarext\webservices\ws_client_core\mw-service-client-core.jar
C:\Users\kkarapet\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
DYNAMIC JAVA PATH
<empty>
So path seems to be set correctly. What am I doing wrong?

With the help of MathWorks support, I've found the answer. Here is how to make JDDE work with Matlab 2012b, without admin privileges:
Download and unpack JDDE files (DLLs and JAR) into some folder. Let's say it's $path-to-jdde$\.
In Matlab, type prefdir. Open the resulting directory and create two files there, javaclasspath.txt and javalibrarypath.txt.
In javaclasspath.txt, add $path-to-jdde$\pretty-tools-JDDE-2.0.3.jar.
In javalibrarypath.txt, add $path-to-jdde$\.
Restart Matlab.
Now call ddeConv = com.pretty_tools.dde.client.DDEClientConversation; and start using the created object as described in JavaDoc. E.g. to connect to Zemax, run Zemax and then in call ddeConv.connect('Zemax', 'abc').
Step 2 above can only be done starting Matlab version R2012b. With an older version, if you have the write rights on the Matlab installation directory, you should be able to replace step 2 by editing the files librarypath.txt and classpath.txt in $MATLABROOT$\toolbox\local. I could not verify it so if you confirm it please let me know in the comment below.

Related

C# calling Java code loading unmanaged dll

I'm working with some java code wich loads an unmanaged dll, just as the following:
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
It works fine from eclipse or console.
Next step: I'm using IKVM tools to get a managed dll from my java app (ikvmc.exe). Everything works fine and my dll is built perfectly. In fact, I've imported that library in a Test Solution (and I've add all IKVM refereces needed -IKVM.Core.JDK, IKVM.Runtime.JNI, etc-).
Well, here is the problem: when I run C# code the java call to System.loadLibrary(...) fails and I get an "UnsatisfiedLinkError: Can't load absolute_path_to_my_dll.dll". Absolute path is ok and dll is there.
Any help? Thanks in advance.
Edit 1
I'll try to explain more in detail:
Java step
public void Foo(){
System.loadLibrary("absolute_path_to_my_dll.dll")
}
If path is not correct this call gives the "UnsatisfiedLinkError" mentioned above. This is not the case, everything works well. The dll file is a 32 bit one, so I compiled this java project with jre7 x86 (in 64 bit mode loadLibrary call falis, obviously, saying we can't load 32 bit dll in 64 bit AMD machine).
Ikvm step
Now I compile java code in a managed dll wich can be imported in a .net project. First of all I export my java project to a jar file, "myJar.jar". Then i apply ikvmc.exe to generate a managed dll, let's say "myNewDll.dll".
ikvm.exe -target:library -out:"myNewDll.dll" "myJar.jar"
This step works nicely and i get a new dll I can import in my VS project.
C# step
Now I create a new VS tester solution. I add "myNewDll.dll" as reference so I can use it in my C# code. Also, I add IKVM.Core.JDK reference (if not, project can't compile) and configure project in 32 bit mode. Problems start here:
Running this setup gives "IKVM.Runtime.JNI error". I've added that reference.
Running again gives "can't find ikvm-native". As I can't add ikvm-native-win32-x86.dll or ikvm-native-win32-x64.dll as reference I put both of them in output path (bin/Debug).
Next try it gives the "UnsatisfiedLinkError: Can't load xxx.dll".
How can it be possible if that dll is loaded flawlessly in java step?
Annother try
Just before start crying I tried annother way: I created a java main program that only called Foo(). Then I generated an executable file with ikvmc.exe tool and called it in windows console. It gave me the same error, UnsatisfiedLinkError so maybe it's ikvmc.exe problem but I can't understand why.
Any idea?
Edit 2
Good news. It seems I've solved the problem. First of all, I had to add -platform:x86 to ikvmc.exe call (step 2). The dll generated was succesfully imported in my C# project and it works fine if we run in execution mode (NOT debugging). If I try to debug in VS it gives me System.Runtime.InteropServices.SEHException.
Is there any kind of bug related to debugging native code (dll loaded in java code) under native code (that java code loaded in C# using ikvm)?
Is your dll a 32 bit and you run it on a 64 bit platform?
If yes then the problem is that IKVM is platform independent. This means on a 64 bit system it runs 64 bit process.
To solve this you need a 64 bit version of your dll or mark ikvm.exe as 32 bit process.
Adding an option of reference to IKVM.OpenJDK.Core.dll at ikvm's /bin directory will resolve the error.
Maybe the .jar file needs some native DLLs, which was same as Native library location parameter of JAR in Eclipse. If so, find the native DLLs and copy them to de /bin directory of IKVM, and make ikvmc to load them automatically.
That's all what I've found out. Try and see if it would bring some ideas.

Compiling standalone selenium: Failed to load Main-Class manifest attribute from

I'm a total Java noob so please understand =) I need a quick advice on how to fix the issue.
I cloned the official selenium git repo, changed the code a bit (need to dump the page into some specified dirs), and tried to rebuilt it:
./go //java/server/src/org/openqa/selenium/remote/server:server:uber //java/client/src/org/openqa/selenium:client-combined:uber
It was successful but when I tried to execute it I got this:
$ java -jar build/java/server/src/org/openqa/selenium/remote/server/server-standalone.jar
Failed to load Main-Class manifest attribute from
build/java/server/src/org/openqa/selenium/remote/server/server-standalone.jar
Tried to check classpath, CLASS_PATH and CLASSPATH env variables (as a friend of mine suggested) - I simply don't have any.
At the same time, the pre-compiled standalone server from the official downloads works out of the box.
The official docs didn't help. There's nothing about it there.
So - I need a quick advice how to compile it? Thanks.
P.S. JDK 8 (latest), Mac OS 10.7
P.P.S. That friend of mine tried to build it by himself and he was lucky - he got a new build/dist folder where the target big file was. But in my case, the build folder is created, but there's not 'dist' folder in it.
Finally found the answer: I should have built it like that:
./go clean release
it's really strange that all the docs state I need to use these long /bla/bla/:uber things to get a whole single 'uber' server.

How to Define Paths to Frameworks on a Mac in Java?

I am helping to code a stop-motion program that is to be cross platform, and on windows it works great. For those who do not know, stop motion is just a fancy term for animation. This program allows users to plug in Nikons, Canons, and Webcams into the computer, and have the program display a live view of the scene, and then have the ability to manually control the camera from there. Included is a framework file from canon for the camera, with a path defined as shown
import com.sun.jna.Native;
initialization and such
public static EdSdkLibrary EDSDK = (EdSdkLibrary) Native.loadLibrary("Macintosh/EDSDK.framework/EDSDK",EdSdkLibrary.class, options);
The error is thrown at the "public static int..." saying that the image is not found. I have tried numerous times redefining the path, moving the framework, and using various other frameworks identical to the one I'm using. Remember, this works flawlessly on Windows, but on Mac there is a problem.
Are frameworks different on macs, or are they to be defined differently? I have looked and found no other solutions.
EDIT: Okay, I defined the path and it now has this symbol > with no text next to it. WHat do I do now?
EDIT: It is saying that this % is not a command. Without it, it still fails to work.
JNA will successively attempt to load frameworks from ~/Library/Frameworks, /Library/Frameworks, and /System/Library/Frameworks, based on the core framework name (EDSDK in this case).
If the loadLibrary call succeeds, then the library was found. If the library was not found, you'll get an UnsatisfiedLinkError.
Frameworks are basically bundles of a shared library with other resources; ESDK.framework/ESDK is the actual shared library (for frameworks, OSX omits the "dyld" suffix normally found on a shared library on OSX).
EDIT
Here's how to make a symlink so that the paths look more like what JNA is expecting. From a terminal (run Terminal.app):
% ln -s /your/complete/path/to/Macintosh/EDSDK.framework ~/Library/Frameworks/EDSDK.framework
When this is done successfully, you should see the following when listing (ls) the symlink:
% ls -l ~/Library/Frameworks/EDSDK.framework
lrwxrwxr-x 1 YOU YOU 50 Mar 31 01:13 /Users/YOU/Library/Frameworks/EDSDK.framework -> /your/complete/path/to/Macintosh/EDSDK/Framework/EDSDK.framework
You should see the symlink path (where JNA will look) on the left, with the path to the real file on the right. If not, delete the symlink file and try again. Note that you may need to create the directory ~/Library/Frameworks first; it may not yet exist.
Finally, make sure that the library you're trying to load matches the VM you're trying to load with; 64-bit with 64-bit, 32-bit with 32-bit. Canon does not provide a universal binary of their library, so you'll need to point to one or the other or merge the two using lipo.
Not really an answer, but more information on the same problem, which I'm experiencing myself.
I can add that JNA will find my frameworks if they're in one of the standard public locations an executable looks for its frameworks, i.e.
~/Library/Frameworks - (public frameworks for the use of the current user)
/Library/Frameworks - (public frameworks for the use of any user)
/System/Library/Frameworks - (public system frameworks)
However, If I want my custom framework to be private - i.e. - not discoverable to other processes than my java vm -- then for some reason JNA doesn't do it.
I know MacOS dynamic loader, when trying to locate a library/framework for any normal (native) MacOS process, does NOT start searching the above locations, but first within several standard "private" locations: (also known as rpath search-path)
in the "Frameworks" directory at the same location as the binary from which the process was loaded: e.g. path/to/my/binary/Frameworks/mySDK.framework
in the "Frameworks" directory at the place where dynamic loader loaded the process (in Application bundles, that would be the myApp.app/Contents/Frameworks/mySDK.framework folder.
So, you can usually create a 'Frameworks' directory of your own right next to your binary, and place your framework in it.
However - JNA misses that. I tried to create a "Frameworks" directory within the "Zulu" - in zulu-11.jre/Contents/Home/bin right next to the 'java' binary, and in other places - but JNA won't find in any of them.
I wonder why, and if there is any documentation for that.
The trick of installing a symlink to my custom framework in /Library/Frameworks may serve you, but I cannot allow other processes to find or load my framework.

MissingResourceException running MXJ for MySQL

I'm using the code from this tutorial for using MXJ to "embed" MySQL in my java application. However, I'm getting this exception when running the code:
Exception in thread "main" java.util.MissingResourceException: Resource '5-5-9/Windows_7-amd64/mysqld.exe' not found
This happens when I reach this line in the tutorial:
mysqldResource.start("test-mysqld-thread", database_options);
I'm running in Eclipse and I have the 4 following jars added to my build path, since this link says I need them:
mysql-connector-java-5.1.18-bin.jar
mysql-connector-mxj-gpl-5-0-12-db-files.jar
mysql-connector-mxj-gpl-5-0-12.jar
aspectjrt-1.6.9.jar
I'm not sure what I'm missing here. Any tips?
MXJ doesn't come ready for use with Windows 7 64 bit. Using this bug ticket, I found what I needed to do.
Once the files are downloaded and extracted from the zips, unjar mysql-connector-mxj-gpl-5-0-12-db-files.jar and add a line to platform-map.properties file inside:
Windows_7-amd64=Win-x86
Save, and re-jar. Works like a charm!
Actually it's never a good idea to mess up with the jar files, cause whenever you upgrade to a newer version you'll need to remember to redo this fix again. The answer is correct, but you just need to create platform-map.properties file with this inside:
Windows_7-amd64=Win-x86
and add it to your classpath.
For anyone who has the same issue on MacOS Catalina, you can follow the README.md in my repo (https://github.com/pengyue/mysql-connector-mxj-mac-os-catalina), which has the 64 bits executables for MacOS Catalina, and this improved connector works on Catalina.
To explain what I have done:
Download the 64 bits executables from MySQL to the folder 5-5-9
Add the platform mapping for 64 bits MacOS in platform-map.properties
Create a jar by using jar cvf mysql-connector-mxj-db-files-5.0.12.jar .
Replace the jar in your mvn settings folder ~/.m2/repository/mysql/mysql-connector-mxj-db-files/5.0.12/ with the jar you just created.
This solution works fine for my projects, Unfortunately I could not find a github for the mysql-connector-mxj, as it is deprecated and not maintainable anymore.
The other option is to use wix-embedded-mysql(https://github.com/wix/wix-embedded-mysql) instead of mysql-connector-mxj, but this probably requires some code changes in your projects.

Stuck at converting/implementing Qt (.ui) files to Qtjambi(.jui) files

Edit 01.02.2012:
FWIW: 4.7.0 linux packages are broken AFAIK, they
can be fixed or 4.6 packages used instead...
No need to use
custom Qt for Jambi – Smar 2 days ago
Thanks to SMAR, I was finally able to resolve this
issue by downloading the an older version of
qtjambi 4.6.3 ( http://qt-jambi.org/downloads/ ). The only problem was that the
designer did not know where to find my jvm which
I solved by adding these two entries to /etc/bash.bashrc:
# custom PATH exports
export JAVA_HOME=/usr/lib/jvm/java-6-sun
PATH=$PATH:$JAVA_HOME/bin
Then I just had to run (everything was in the qtjambi-folder):
designer.sh --> save it as .jui --> convert it with juic into a .java file --> and load it with netbeans :)
Hope this is somehow helpful to others too.
Thanks for the great and fast help!
Original post:
Good evening,
I am not completely sure if this topic is enough about programming but I am having some problems setting up Qtjambi. I have followed a lot of "howtos" and instructions so I am a little confused about what to do next. Qtjambi works as I have written a example program with netbeans. Although I have created some ui files that I want to implement which doesnt work.
I am trying to get this to run for like a week and I really need this because of my finals in 2 months. I try to give as much useful details as possible.
I am using LinuxMint (ubuntu derivate), downloaded qtjambi v 4.7.0
after trying out
bash qtjambi.sh
I got an error of mismatching versions
Cannot mix incompatible Qt library (version 0x40704) with this library (version 0x40700)
So I downloaded, compiled and installed
qt-everywhere-opensource-src-4.7.0 to /usr/local/Trolltech/Qt-4.7.0/
I know that I have to tell the system where to find all the binarys so I added to the /etc/bash.bashrc
#custom PATH exports
PATH=$PATH:/home/michi/Scripts
PATH=$PATH:/usr/local/Trolltech/Qt-4.7.0/bin/
export LD_LIBRARY_PATH=/usr/local/Trolltech/Qt-4.7.0/lib
export QT_PLUGIN_PATH=/usr/local/Trolltech/Qt-4.7.0/plugins
JAVA_DIR=/usr/lib/jvm/java-6-sun-1.6.0.26/
export JAMBI_PATH=/usr/local/lib/qtjambi-linux64-community-4.7.0/
I followed through the instructions of:
http://www.davidlauzon.net/2010/01/getting-started-with-qt-jambi-on-linux/
Which generally talks about getting jambi-designer to work.
http://jpnurmi.kapsi.fi/blog/2008/03/16/how-to-switch-qt-version-in-ubuntu/
How to manage multiple Qt versions.. These commands worked but had no effect
I finally gave up on trying to run the designer and tried to "convert" the .ui files to .jui files with the program juic which is located in the qtjambi/bin folder. But also here I get an error:
michi#BALMORA ~/Documents/unterlagen/pr_scw/Qt/Qtrainer/test $ which juic
/usr/local/bin/juic
michi#BALMORA ~/Documents/unterlagen/pr_scw/Qt/Qtrainer/test $ juic -cp .
juic: no .jui files found in CLASSPATH
michi#BALMORA ~/Documents/unterlagen/pr_scw/Qt/Qtrainer/test $ /usr/locallib/qtjambi-linux64-community-4.7.0/bin/juic -cp .
juic: no .jui files found in CLASSPATH
It would be great if you could help/guide or redirect me to "better" instructions.
Michael Kargl

Categories