Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is it possible to call the C code (which has been generated py Beremiz Editor) from java?
I dont want to edit the generated C code i just want to call it from my Java program.
Instead of modifying the generated code, you can write a bridge in C that would accept calls from Java and forward them to your generated code. It can be compiled together with the generated code, making the single .dll or .so library.
JNI interface has many specific requirements and agreements. It cannot be used to call the arbitrary C function that was written without having JNI in mind.
This is a very common task when integrating existing C libraries into Java framework.
You can use JNI to do this, a good tutorial is available here:
https://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html
This allows you to call your C code from in java.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to decide if JNI is for our use case.
We have a library written in C++ that fetches data from Database/RPC using multiple threads, and we want to create a wrapper to let Java code be able to call it.
I'm not familiar with JNI, so I would like to know if C++ multithreading will still work properly in this case.
Thanks.
I don't see any major issues in neither direction. Unless you have something really specific.
Here you have sample that calls JNI code from multiple threads:
http://jnicookbook.owsiak.org/recipe-No-024/
Here you have sample that calls Java from multiple C threads:
http://jnicookbook.owsiak.org/recipe-no-027/
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What is the most efficient way of passing data from C++ to Java?
The Java application will need to call the C++ application to retrieve the data.
I can see the following ways of achieving this:
Using JNI
Using a file based approach
Using SWIG
My current thinking is to use JNI. AM I missing a better method before I commit?
Java Native Interface allows you to pass anything back and forth between C++ and Java. It supports both directions, but can be tricky. There are others you can look at Swig is one and then you have JNA. I would go with JNI
JNI would be the best approach. Notice that javah creates compatible header-files for your java-class, its very tricky to to write compatible header-files by your own, so please use javah.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have written an RTMPS client a while back and needed it for my Django application but since Java and Python don't play well without using system calls (I don't want to use Jython) I wanted to rewrite the application in Python.
Would it work if I ported it as if to Python from Java? Of course we have to take into account the obvious things like multiple constructors have to be done differently in Python. Are there any other things that would not make it work in Python?
I am doing this because Java is so memory heavy and hoping that moving in into Python would reduce memory footprint and thus allow my web app to use it.
I would suggest rewriting it completely but there are a lot of differences to take into account. Here's a starter for recognizing some of the common differences/mistakes: http://dirtsimple.org/2004/12/python-is-not-java.html
Also if you are too lazy to rewrite the code (like me) there is an other option: java2python
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am kind of stuck in a dilemma. I want to create a tool that would generate code on the fly by taking various parameters from the user. The codes have a few similar features and few things need to be altered from one code to other to other. Based on the parameters, I can have 15 different codes. Till now I have been using file handling in Java to implement this as I have the created codes in different files but this doesn't seem to be a great method. Can you please suggest something that is better than this??
Since Java 1.6 you can compile in memory whatever you want. Take a look at this code:
http://code.google.com/p/cachos/source/browse/trunk/cachos/src/com/peyrona/cachos/InMemoryCompiler.java
http://code.google.com/p/cachos/source/browse/trunk/cachos/src/com/peyrona/cachos/InMemoryExecutor.java
In this example you can see how you can compile a source code stored in a String in memory, without using the disk.
Source (Spanish): http://www.javahispano.org/portada/2011/12/12/compilar-y-ejecutar-codigo-java-en-memoria.html
I think this is what you're looking for.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there any way that a .c and .h files can be used in eclipse? On a 32 bit xp,using jre1.6. I do not know any C. The code is about 500 lines
Not directly. You would need to know some c to add interface methods to be able to use JNI.
JNI is the key to use c or c++ code.
You can either invoke it using JNA or JNI, JNA generally being the easier one to use.
You'll need to alter your code though by reading up on the two technologies - it's not a magic bullet.
Your best bet is to rewrite the code.
Any kind of automated conversion usually produces unmaintainable code. If you opt for this solution, just pick one of these :
http://tech.novosoft-us.com/product_c2j.jsp
http://www.soften.ktu.lt/~stonis/c2java/