I am writing a Java Swing program which collects data and connects to Mathematica to do some computations. As other answers here suggested, I have included JLink.jar in the classpath, as well as the various JLinkNativeLibrary.dll and libJLinkNativeLibrary.so for compatibility with Linux and Windows.

If launched from the Eclipse IDE the program is able to load JLink.jar, and prompts me to "choose a mathlink program to launch", which is fine because Mathematica is not installed on my PC. However, when compiled and launched from the .jar, the program freezes as (in my opinion) it can't find JLink.jar.

The structure of the .jar folder is as follows:


Having JLink.jar in the same folder as myProgram.jar does not help. In the BuildPath configurations, I have included JLink.jar as a library and all the JLink folder from Mathematica as a source folder. In my opinion, the code that fails (because before adding it the IDE version of the program behaved in the same way as the .jar) is the setProperty() instruction:

System.setProperty("com.wolfram.jlink.libdir", mainProgram.getLocation());

which I set to the location of the .jar file hoping that in this way the JLink.jar would have been found, being it in the same folder as myProgram.jar.

For completeness, I will also add the "whole" connection procedure:

KernelLink ml = null;
    try {
        System.setProperty("com.wolfram.jlink.libdir", mainProgram.getMainLocation());
        ml = MathLinkFactory.createKernelLink(getDefaultConnectString());

Any hint? If deemed useful, I can provide more details.

  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour. 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise $\endgroup$ – Sjoerd C. de Vries Jun 5 '15 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.