0

I want to call the opensource MATIEC Compiler from my Java program.I have seen a lot of tutorials related to JNI(Java Native Interface) but all the examples and tutorial only deal with very simple HelloWorld programs.I want to know that for the large code like MATIEC Compiler how I can access that program from java? I have tried the JNI tutorial and I understand this example completely.But I am confused in how to deal a large source code file.

Suleman
  • 11
  • 2
  • SO works best with specific questions. _"I don't know how to do what I want to do"_ is a little too general. – Richard Critten Oct 13 '17 at 10:51
  • Yes sure i am reading the page how to improve question. But in the mean time i thought i should ask my question. – Suleman Oct 13 '17 at 10:53
  • Don't do that, and if you already did that don't admit to it, people are not going to like it ... you're supposed to read first, ask later(or understand that your question is not suitable for this site which is the case with this question). – Oleg Oct 13 '17 at 10:55
  • You can **call it** just by using command lines from java via `Process`es. You don't even describe what exactly is your goal, neither didn't you describe why helloworld tutorials are not helpful to you (argument to your task being bigger is moot, all big tasks are composed of smaller subtasks solvable separately). – M. Prokhorov Oct 13 '17 at 10:58
  • @M.Prokhorov I have to pass the structured text file to the MATIEC compiler from the java and then this compiler will check the lexical and semantic analysis of the ST file and generate the java bytecode. – Suleman Oct 13 '17 at 11:05
  • @Suleman, Java can't pass around files. You can rig it to pass file descriptor, file identifier, or a bytestream, and all those things can equally be done via Process/command line. – M. Prokhorov Oct 13 '17 at 11:08
  • I think browsing the JNA source code, especially their wrapping of Win32, will give you a good idea – Werner Erasmus Oct 13 '17 at 11:11
  • @WernerErasmus I have studied about JNA and it was written that JNA doesn't support C++. Is it right? – Suleman Oct 13 '17 at 11:23
  • @Suleman, JNI (and JNA) has a native component that is written in c++ – Werner Erasmus Oct 13 '17 at 12:58
  • Also, when it comes to: JNI vs. JNA vs. Process, take a look here: https://github.com/mkowsiak/jnicookbook/tree/master/recipeNo033 where you can find little bit more when it comes to execution time of the same code using different methods. – Oo.oO Oct 13 '17 at 17:37
  • @Suleman, neither of JNA and JNI support C++ (but you can still call C++ compiled code). You need to go via C or C externs inside C++. BTW. JNA is (eventually) using JNI at some point. It's just more convenient way of accessing native code. – Oo.oO Oct 14 '17 at 09:15

1 Answers1

1

If you are looking for more complex tutorial, take a look here:

http://jnicookbook.owsiak.org

You have even recipe for adapting C++ code:

https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo025

and you have sample where you can get familiar with concepts of accessing object's fields, etc.

http://jnicookbook.owsiak.org/recipe-No-020/

All sorts of topics that are real life examples and not just simple Hello World. Even though it starts with Hello World.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45