We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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.


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

export LD_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/server
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)

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.