3
$\begingroup$

I have no trouble compiling and running the sample Java to Mathematica program SampleProgram.java that can be found in the Wolfram installation:

FileNames["SampleProgram.java", {$InstallationDirectory}, Infinity]
(* {"/usr/local/Wolfram/Mathematica/10.2/SystemFiles/Links/JLink/Examples/Part2/SampleProgram.java"} *)

When I try to compile and run a modified copy of this program from a different directory I get the following error message:

Error: Could not find or load main class files.wolfram

It seems it should be looking for com.wolfram.jlink.*. I am quite sure the classpath to JLink.jar is correct.

Does JLink.jar contain a manifest pointing to some other resource that it cannot find?

Any help you could provide would be greatly appreciated.

$\endgroup$
3
  • $\begingroup$ That really sounds like a classpath issue even though you've checked it. If you don't modify the program and run it from the other location, does it work? Does the modified program work in the Wolfram directory tree? Are you having problems running javac (compiling) or java (running)? -- (no, there is no reference to files.wolfram in the manifest.) $\endgroup$
    – ZachB
    Commented Oct 1, 2015 at 5:34
  • $\begingroup$ @John Are you no longer interested in your question? I mean, why do you give a bounty on a question and then never show up to discuss your problem? $\endgroup$
    – halirutan
    Commented Oct 7, 2015 at 19:55
  • $\begingroup$ @halirutan I was trying to help a student with a project. The issue did not occur on the student's computer. So we have moved beyond this as an emergency issue. $\endgroup$
    – John McGee
    Commented Oct 9, 2015 at 10:36

1 Answer 1

3
+25
$\begingroup$

Unless you tell us exactly what you typed on the commandline, there is no way of knowing what went wrong.

Let me give you a head-start. My Mathematica installation is in the directory

/usr/local/Wolfram/Mathematica/10.2

Therefore, to start the SampleProgram I go into the directory where SampleProgram.class is and type

java -classpath \
  ".:/usr/local/Wolfram/Mathematica/10.2/SystemFiles/Links/JLink/JLink.jar" \
  SampleProgram -linkmode launch -linkname 'math -mathlink'

and I get the following output

2 + 2 = 4
3 + 3 = 6
4 + 4 = 8

If you are working on Windows, then your command should look like

java -classpath ".;\path\to\JLink.jar" 
  SampleProgram -linkmode launch 
  -linkname "c:/program files/wolfram research/mathematica/8.0/mathkernel.exe"
$\endgroup$
1
  • $\begingroup$ This works on my computer also. The problem arises when I try to move the SampleProgram.java to a directory outside the wolfram file tree. $\endgroup$
    – John McGee
    Commented Oct 9, 2015 at 10:33

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.