I'm trying to make a java servlet running on Tomcat 7 for specilized mathematical calculations. So I want to link Wolfram Mathematica 8.0 mathkernel from my servlet via JLink (webMathmatica is not an option). I placed JLink.jar and JLinkNativeLibrary.dll into WebContent/WEB-INF/lib directory and wrote the following code:

String[] mlArgs = {"-linkmode", "launch", "-linkname", "\"path-to-mathkernel.exe\""};
mathKernelLink = MathLinkFactory.createKernelLink(mlArgs);

But, when I launch my servlet on Tomcat, it shows dilog box with title "Choose a MathLink programm to launch". If I choose mathkernel.exe from the Mathematica folder, further calculations run fine. I think that "path-to-mathkernel.exe" is incorrect to automaticaly run mathkernel.exe. I tried to use a global path c:\program files\wolfram research\mathematica\8.0\mathkernel.exe, but i didn't succeed.

Witch path should I use? Or should I configure Tomcat to run external applications? Thanks.


2 Answers 2


I recommend you check if the licensing terms even allow you to do that. Last time I checked (and my knowledge on this is a bit outdated), it was not permitted to use M in a web/network environment. If you do, the webM license immediately applies. You are basically trying to implement a feature that is substantially similar to a core feature of webM: slave the kernel to tomcat. Really, check if this is legal. I believe for what you're trying to do the webM license applies, making this is a license violation.

  • $\begingroup$ Nice to finally see you here, Andreas! I had no idea that such a use of M kernel would constitute a license violation - I thought if you have a commercial license, then you can use M as a part of any infrastructure you want, being limited only by the CPU cycles of your computer. $\endgroup$ Commented Jun 28, 2012 at 20:01
  • $\begingroup$ Leonid, it MAY very well be legal to do so if you have a webM license. Don't know. But the o/p didn't indicate that. In fact, the o/p said that webM was NOT an option. And in that case I know FOR SURE this is not legal, unless that has changed in the last few yeasr. $\endgroup$ Commented Jun 28, 2012 at 20:07
  • $\begingroup$ Ok, I see. It is an interesting bit of information. From what I can see on the page with commercial license terms, webMathematica is included, but that has to be double-checked I guess. In any case, +1 for mentioning this subtlety - it should be a very important thing to check for anybody who wants to use Mathematica as a computational engine of their apps. $\endgroup$ Commented Jun 28, 2012 at 20:12
  • 1
    $\begingroup$ Found it. Point (f) under prohibited uses. $\endgroup$
    – Szabolcs
    Commented Jun 28, 2012 at 20:27
  • 2
    $\begingroup$ @Symbolist In fact, the prohibited uses section of the license only states that it is illegal to allow access to anyone except the one who is licensed to use M. So, if you never make your system available to others, it may be that you can complete your experiment without breaking the license terms. But I am not a lawyer, this is just a guess which must be checked. $\endgroup$ Commented Jun 28, 2012 at 20:47

be sure to escape the backslashes, as in "c:\\program files\\wolfram research\\mathematica\\8.0\\mathkernel.exe", and try again. I can't imagine that there would be code in MathLinkFactory that checks whether or not the call originated from Tomcat or not - I think that's even technically impossible.

I works for me as you did it (with absolute path to mathkernel, without Tomcat), so it MUST (technically) work with Tomcat too.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.