views:

166

answers:

2

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
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
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
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
I don't know, but I guess it's a path issue.
High Performance Mark
+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
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
You could try loading your VariableGraph class in Mathematica and trying to initialize it with your data file.
BaroqueBobcat