Run a java program inside Matlab with a input file.
8 views (last 30 days)
Show older comments
Hi, I'm tring to run a java program from a matlab code. I already added the .jar file in the system static variables and I achived to lounch the progam. However I need to use a input file wrote inside matlab as a .txt file (or .dat dosen't matter). I'm using the system function:
system('java -jar mhclasses.jar');
system('java -jar javafoil.jar' );
where i can put the input file?
3 Comments
Accepted Answer
Kojiro Saito
on 7 Dec 2021
Edited: Kojiro Saito
on 7 Dec 2021
I'm not familiar with JavaFoil, but it seems that "Script" option allows input files. If you want to input data.txt, try this.
!java.exe -cp "java\mhclasses.jar" -jar "java\javafoil.jar" Script="data.txt"
Alternatively, JavaFoil has embedded sample java code in Embedding and you can use it in MATLAB.
javaFoilPath = "C:\Path\To\MH AeroTools\JavaFoil\java";
javaaddpath(fullfile(javaFoilPath, 'mhclasses.jar'))
javaaddpath(fullfile(javaFoilPath, 'javafoil.jar'))
import MH.JavaFoil.*;
jf = JavaFoil;
% Start JavaFoil embedding
jf.startEmbedded ;
jf.runScriptLine("Options.Country(0)");
% You can input using CreateAirfoil
%jf.runScriptLine("Geometry.CreateAirfoil(0,121,12,30,0.000,40.000,0,0,1)");
% It seems that you can input txt file
jf.runScriptLine("Geometry.Open('data.txt')")
jf.runScriptLine("Polar.Analyze(500000,500000,100000,-5,15,1,100,100,0,0)");
jf.runScriptLine("Polar.Save('polar.txt')"); % Save the result
% Close JavaFoil embedding
jf.exitEmbedded;
clear jf
Again, I'm not familiar with JavaFoil, and it is rather JavaFoil specific question than MATLAB, so if you have further question, I think it's better to ask in JavaFoil community.
More Answers (0)
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!