Hi, Could you please give me a hint how can I invoke a java project (written in eclipse) from Mathematica? I want to give values generated by my Mathematica program as input to a java project, and use the (outputs) results obtained from solving the problem by java, as input to my Mathematica code. I know there is a J/Link package for calling java from mathematica. But, i don't know how I can have this interaction between them.
+2
A:
Hi
Can you confirm that you have studied the online documentation at Wolfram's website and perhaps be more specific about your questions ? If you haven't I suggest that you do, it's comprehensive and relatively useful.
Regards
Mark
High Performance Mark
2010-02-01 13:01:51
Since I am not familiar with java, I don't know from which part of that document I can find the answer. I guess it must be under "Debugging Your Java Classes" title. The things I need to know are: first, how to make an executable version of my java project; then, how to execute it in Mathematica. To avoid memory sharing and other complicated problems I want to give java project inputs generated in Mathematica via a file, and also use the outputs generated by java (written in a file) in my Mathematica code.
Matin
2010-02-02 09:42:57
Well, if you are not familiar with Java you are going to find it difficult, until you are, to make an executable version of your project. I suggest you do that first, then return to the Mathematica side of your problem. Point your browser at http://www.wolfram.com/solutions/mathlink/jlink/ for documentation on JLink. But, from your comment, you don't actually seem to want to use JLink, but to be satisfied with writing a file from Mathematica and reading it in Java. This should be very easy to implement.
High Performance Mark
2010-02-02 12:49:55
I made a jar file from my project which is run with no problem from command prompt. However, when I run it in Mathematica with Run[.] command, it gives me the following error: "java.io.FileNotFoundException: data\test_7 (The system cannot find the path specified)" for an input file, which is called from within my java program like this: static Graph graph = new VariableGraph("C:\\Mas\\data\\test_7"); How should I define the paths to be able to get rid of this error and run my jar file in Mathematica?
Matin
2010-02-06 17:26:45
I don't know, but I guess it's a path issue.
High Performance Mark
2010-02-07 15:19:48
+3
A:
Assuming your project is on the class path, you can pull in Java pretty easily(see docs)
Needs["JLink`"];
InstallJava[];
awesomeClass = LoadJavaClass["my.java.class.OfAwesomeness"];
awesomeClass`crazyStaticMethod[];
awesomeInstance = JavaNew[awesomeClass,"Awesome Arg 1"];
awesomeInstance@superCoolMethod[1,2,3];
BaroqueBobcat
2010-02-02 23:01:22
I made a jar file from my project which is run with no problem from command prompt. However, when I run it in Mathematica with Run[.] command, it gives me the following error:"java.io.FileNotFoundException: data\test_7 (The system cannot find the path specified)"for an input file, which is called from within my java program like this:static Graph graph = new VariableGraph("C:\\Mas\\data\\test_7");How should I define the paths to be able to get rid of this error and run my jar file in Mathematica?
Matin
2010-02-06 17:26:10
You could try loading your VariableGraph class in Mathematica and trying to initialize it with your data file.
BaroqueBobcat
2010-02-07 17:22:34