1
$\begingroup$

I tried the following command in notebook. It creates a .cdf file.

CDFDeploy["C:\\Users\\Admin\\Desktop\\myfile.cdf", 
 Manipulate[Plot[x^a, {x, 1, 100}], {a, 1, 10}]]

But when I tried the same in external java program, its giving $Failed.

import com.wolfram.jlink.KernelLink;
import com.wolfram.jlink.MathLinkException;
import com.wolfram.jlink.MathLinkFactory;

public class testrun {

public static void main(String[] args) {
    KernelLink ml = null;

    try {
        ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'C:/Program Files/Wolfram Research/Mathematica/10.2/MathKernel.exe'");
    } catch (MathLinkException e) {
        System.out.println("Fatal error opening link: " + e.getMessage());
        return;
    }

    try {
        // Get rid of the initial InputNamePacket the kernel will send
        // when it is launched.
        ml.discardAnswer();

        System.out.println(ml.evaluateToOutputForm("CDFDeploy[\"C:\\Users\\Admin\\Desktop\\myfile.cdf\",Manipulate[Plot[x^a,{x,1,100}],{a,1,10}]]",0));

    } catch (MathLinkException e) {
        System.out.println("MathLinkException occurred: " + e.getMessage());
    } finally {
        ml.close();
    }
}
}
$\endgroup$
0

1 Answer 1

1
$\begingroup$

Wrapping CDFDeploy with UsingFrontEnd does the trick

$\endgroup$

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.