Run a java program inside Matlab with a input file.

2 views (last 30 days)
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?
luigi ventre
luigi ventre on 2 Dec 2021
nothing changes... I recive this message every time i run the script: 'no main manifest attribute, in mhclasses.jar'. The mhclasses.jar is a .jar file that i need to load to run javafoil.jar. On the user guide of this program (javafoil) looks like there is the possibility to run a main script (there are some exemple of java script to run)...
this is one of them:
// A simple JavaFoil example which creates a two element
// airfoil for downforce generation.
// switch to US country settings
// create a cambered NACA airfoil for starting
// create a copy of this first airfoil element to be used later
// now select the first element again
// ... flip it upside down
// ... scale it to 75%
// ... rotate it 5 degrees trailing edge up around its nose (0;0)
// now select the second element
// ... flip it upside down
// ... scale this copy to 30%
// ... move it back so that there is 5% overlap
// ...rotate it by 30 degrees around a point at (70%/12%)
// finally: (THIS IS OMPORTANT!)
// select both elements again for all further analyses
// if only one element is selected on the modify card, only this element
// will be considered during the calculation of polars etc.!
// and move both elements up by 25% for ground clearance
// (note that the airfoil may not cross the y=0 line which is the ground
// switch ground effect simulation ON
// prepare for analysis
// velocity versus x/c should show no strong suction peaks in the
// nose region of 2nd element
// polar for Re=500'000, alfa=-15 to +10 degrees
// with ground present a string suction force is generated
// (even for single element airfoils)
// therefore a Cl_min in the order of -5 to -6 can be seen.
// finally: export coordinates in XML format
Onestly this is my first time with java....

Sign in to comment.

Accepted Answer

Kojiro Saito
Kojiro Saito on 7 Dec 2021
Edited: Kojiro Saito on 7 Dec 2021
It might be better to read JavaFoil document.
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 ;
% You can input using CreateAirfoil
% It seems that you can input txt file
jf.runScriptLine("Polar.Save('polar.txt')"); % Save the result
% Close JavaFoil embedding
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.
  1 Comment
luigi ventre
luigi ventre on 7 Dec 2021
you have perfectly answered to my question eaven if you are not practise! thaks!!
I was looking for a method to use javafoil on matlab and save the polars.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!