Deploy Java wrapper around m-file wrapper around a mex file?

조회 수: 3 (최근 30일)
FM
FM 2022년 3월 31일
댓글: FM 2024년 1월 15일
I have successfully used Compiler SDK to deploy a Java wrapper around my home-made m-file wrapper around "intlinprog" (more than just a wrapper, but a wrapper on steroids, adding required functionality).
I would like to do the same for a specific non-native library function for graph layout. Specifically, Kamada-Kawai (KK) layout, which is part of the MATLAB-BGL library, which in turn seems to consist of MATLAB wrappers around a C++ Boost graph library: https://github.com/dgleich/matlab-bgl/blob/master/kamada_kawai_spring_layout.m.
The MATLAB-BGL library contains many files for the KK layout function:
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.c
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexa64
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexglx
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmac
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmaci
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw32
  • matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw64
(1) Can I deploy a Java wrapper of the kamada_kawai_spring_layout.m, or a Java wrapper of my own wrapper of kamada_kawai_spring_layout.m?
(2) Would it be a matter of supplying the above mex files along with the Java package?
(3) I am still on Matlab 2019a, but may be migrated to a newer version soon. For 2019a, however, I need to compile for Windows and Linux separately, e.g., running Compiler SDK on a Windows machine and in an Ubuntu VM. Seeing as the above mex files includes a mexglx, is the compilation process the same, but keeping in mind to supply all the mex files regardless of which OS I'm deploying to?

채택된 답변

Shubham
Shubham 2024년 1월 15일
Hi FM,
  1. Yes, you can deploy a Java wrapper of kamada_kawai_spring_layout.m or a Java wrapper of your own wrapper of kamada_kawai_spring_layout.m. The MATLAB Compiler SDK allows you to create Java packages from your MATLAB code, which can then be called from Java applications. The process involves writing a MATLAB function that acts as an entry-point, compiling it using the MATLAB Compiler SDK, and then integrating the generated Java package into your Java application
  2. When you compile MATLAB code that depends on MEX files using the MATLAB Compiler SDK, it is not necessary to manually supply the MEX files along with the Java package. The compilation process will automatically include all required MEX files in the generated package. The MATLAB Compiler SDK handles the inclusion of platform-specific binaries (like MEX files) when creating the package.
  3. You are correct that you need to compile your MATLAB code for each target operating system separately. Each operating system has its own MEX file binary format (.mexw64 for 64-bit Windows, .mexa64 for 64-bit Linux, .mexmaci for Intel-based Mac, etc.), and the MATLAB Compiler SDK will compile the MEX files appropriate for the OS you are running the compilation on.
  • When deploying on Windows, compile your MATLAB code on a Windows machine to ensure the correct MEX files are generated and included in the package.
  • When deploying on Linux, compile your MATLAB code on a Linux machine to ensure the correct MEX files are generated and included in the package.
  • The MATLAB Compiler SDK will take care of bundling the correct MEX files for the OS you are compiling on. You don't need to manually supply all the MEX files for different operating systems; just compile on the target OS, and the correct MEX files will be included.
Here's a high-level overview of the steps you would take to deploy a Java wrapper:
  • Write a MATLAB function that acts as an entry-point for the functionality you want to expose. This function should call kamada_kawai_spring_layout.m or your own wrapper.
  • Use the MATLAB Compiler SDK to compile this MATLAB function into a Java package.
  • Integrate the generated Java package into your Java application.
Make sure to test your Java application on all target operating systems to ensure that the MEX files work correctly in those environments.
  댓글 수: 1
FM
FM 2024년 1월 15일
Thank you for those detailed steps, Shubham!
The situation has changed a lot since I posted that question. The host Java app is now relying on GraphViz's "stress majorization" implementation and generalization of the Kamada-Kawai model. I appreciate your advice that Compiler SDK must still be run on the target OS to collect the right files. At around R2023a (or maybe R2022a), the compiled *.jar file for the deployed function is cross-platform, so it doesn't need to be compiled by Compiler SDK on each host OS. However, that doesn't necessarily apply to all the MEX files, so your clarification is appreciated. Maybe not for this effort, but for some future effort.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by