Aspose-cells java JNI (c++ call aspose-cells java) on MAC

I have problem to call aspose-cells for java from c++ process (JNI), the program hang up when call constructor JNI java function. My sample code is

public WorkbookWrapper(String fileName) {
try {
wb = new Workbook(fileName);
} catch (Exception ex) {
Logger.getLogger(WorkbookWrapper.class.getName()).log(Level.SEVERE, null, ex);
}
if (wb != null) {
numSheet = wb.getWorksheets().getCount();
}
}

Please help me to resolve this issue,

Hi Duong,


Thank you for considering Aspose APIs.

Could you please try executing the Java code directly against JVM to see if you still can replicate the issue? This is because, if your input spreadsheet is corrupted or have errors then you may not be able to load it in an instance of Workbook. In that case, you have to share your spreadsheet with us so we could properly investigate the matter on our side.

Hi Babar,

This code work well in direct java process, can you help me on JNI call? And JNI also work well on Windows and Ubuntu (with same code). Problem in this case is using aspose-cells for java as a JNI program have problem only on MAC.

Duong

Hi Duong,


Thank you for the additional details. I will discuss this matter with the concerned member of the product team in order to devise a troubleshooting mechanism for you. In the meanwhile, please create an archive of your test project (including dependencies) and share here along with your MAC environment details. Moreover, if you are using any older revision of the Aspose.Cells for Java API, I would request you to give the scenario another try against the latest version, that is; 8.8.0 at the moment.

Hi Babar,

Thanks for your comment, i use latest version of aspose-cells (8.8.0), my sample code running on MAC in attachment,

For build and run:
g++ -o main -I/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/include/darwin -L/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/server -ljvm main.cpp

run:
export LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/server
./main 
Note:
Make sure that you must set file java (WorkbookWrapper.java) in /tmp and build it to class file (javac -cp /tmp:/tmp/aspose-cells-8.8.0.jar:/tmp/aspose-gridweb-8.8.0.jar:/tmp/bcprov-jdk16-146.jar WorkbookWrapper.java); and all aspose-cells jar file must be copied to /tmp before (aspose-cells-8.8.0.jar, aspose-gridweb-8.8.0.jar, bcprov-jdk16-146.jar)
Duong

Hi Duong,


Thank you for sharing the code.

Unfortunately, we currently do not have the required environment (MAC OS) to perform tests and assist your further with this scenario. While we are preparing the suitable environment, could you please perform the following tests on your side?

  1. Instead of loading a template spreadsheet, please create the spreadsheet from scratch; that is, using the default constructor of com.aspose.cells.Workbook class, and save the spreadsheet to disc using Workbook.save method.
  2. If above scenario works fine, please manually create an empty spreadsheet using Excel application in Windows environment, and try loading it in an instance of Workbook class (on MAC OS), as you are doing at the moment.
  3. Try setting the following JVM arguments and execute your original code.
    • -Djava.awt.headless=true
    • -Dawt.toolkit=sun.awt.HToolkit

    Moreover, as the problem is not reproducible in Windows or Linux based environments, this suggests that the problem could also be related to your current configurations in MAC environment therefore I request you to please share the component versions such as of g++ and so on from different environments that you have tested so far.

    Hi Duong,


    I haven’t heard from you for some time so I am wondering if you are able to resolve the said problem. If not, please provide the results for the 3 tests mentioned in the above post. By the way, I have gone thorough a number of threads in Aspose support forums as well as over other community forums in search for similar situations and I came across a situation where Aspose for Java APIs were used via Jpype on OS X. As per customer observations, the process hanged during the conversion of office documents. The situation was resolved by specifying the JVM arguments as mentioned in test 3 of above post. In perspective of Aspose.Cells for Java API, it needs the font information for certain features of the Workbook, and tries to use the FontManager of JDK to get font paths automatically. However, for some environments and different JDK types, the FontManager may not work well and cause error or become unresponsive. The “java.awt.headless=true” is Java’s builtin option and it can avoid the invocation of FontManager.

    @amjad.sahi @babar.raza @loiduongcong Was there a solution to this problem? I am current stuck with exact same issue.

    Invoke Java from C++.

    @ksaurabh
    We recommend you to kindly try using our latest version,
    Aspose.Cells for C++ v24.7.

    For installation on Mac, please refer to the following document.

    If you still find the issue, kindly do share your complete sample (runnable) code and template Excel file (if any) to reproduce the issue on our end, we will check it soon.

    @John.He

    I am using the latest version of Java Aspose Cells. I have created a ticket and in contact with @amjad.sahi. But my issue is identical, call to

    New Workbook() or New Document()
    

    Doesn’t work. It gets hanged.

    @ksaurabh,

    We previously mentioned that there may be conflicts with dependencies or configuration issues in your environment when using the Aspose APIs. If you are using Aspose.Cells for Java within an existing project, we suggest creating a new project with minimal code that only references Aspose.Cells in order to reproduce the issue. This will help determine if the problem is specific to certain configurations or components of your project. Additionally, please zip and share this minimal version of the project with us so that we can evaluate and investigate the issue on our end.

    1 Like

    For anyone in future facing this, please use the headless mode

    -Djava.awt.headless=true 
    or
    System.setProperty("java.awt.headless","true");
    

    and make sure it is set.

    String isHeadless = System.getProperty("java.awt.headless");
    System.out.println("Property is: " + isHeadless);
    

    @ksaurabh,

    Thanks for sharing this and it is nice to know that you were able to figure out your issue by setting the headless mode.