I have a java code and created a jar file.
I need to create an Qt application. Can I use this code in that application?
Please help me how can i use that jar file.
Thanks,
Nagaraju.
You could take a look at the capabilities of GCC/GCJ (see http://gcc.gnu.org/ ). IF it's a good idea is a whole other story, and depends on what you have, and what you're trying to accomplish. It should be doable to link SO's created with GCJ in QT applications, but I seriously wonder if you are not better off using either C++ or Java, but not mixing them
If your Java code takes input from stdin or some file and writes output to stdout or some file, then the easiest way is to fork java to run that jar, and parse the output in your Qt code.
Things other than that, you'll need to be a bit specific. Something like "my Java code does painting the screen".
My advice is to use SWT or Swing.
You can use gcj gcj to compile the java code to library and simply call the functions of the java code from your C code.
Yes, you can use your jar file in your Qt application. I've done exactly this myself.
One way is to use the JNI Invocation API. This is part of the Java Native Interface (JNI), which makes it feasible but not pleasant to access Java APIs from C++.
A much more pleasant approach is to use CodeMesh JunC++ion, which wraps the Java APIs in C++ classes. This is a great product, if you can afford it.
If you have very little Java code, it may be easier to port it to C++.
Related
Is there any way to call the functions which are in a so library from my Java code? Generally, is it possible to use Linux so libraries in Java programs?
The answer is "JNI" :)
Here are a couple of links:
How to compile dynamic library for a JNI application on linux?
http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/
You cannot use arbitrary .so libraries in your Java code. You can use JNI to write a wrapper around native code to access from Java.
However, be aware that doing so negates many of the advantages of using Java. Your code and deployment system now becomes quite fragile and subject to many types of bugs that cannot happen in Java. I would try quite hard to find a pure-Java solution before resorting to using native code.
Another wayto access libraries form java besides JNI is JNA.
I find that in many cases it's easier to use then JNI, but that's just my personal opinion.
I have somoe C# source code that I want to be available for java applications under linux OS.
How can I call some C# method from java code?
I have found http://www.mono-project.com/Java but this looks like writing java code in .net environment. It is not what I look for. Rather I need to create new java library that will expose all functionality from C# code, the new library must be executed in pure java environment. Maybe that is possible with IKVM I am not sure.
Use Mono to compile your C# classes on the Linux platform of your choice;
Use JNI to write a set of facade classes between your java code and the compiled C# code.
The closest tool I can find that might be useful would be JNI4Net
I think you would still need Mono to run a .net framework on Linux as well.
Your question is going to be closed (I voted too) simply because it would finally lead to a tool recommendation.
Your best approach is to rewrite them in Java. Or alternatively, there are existing tools (commercial or free) to convert C# to Java,
CSharpJavaMerger Framework
RemObjects C# who compiles C# to JVM.
and many others
Mono is not something you should consider at this moment. Yes, IKVM.NET only helps running Java code on Mono/.NET, and it won't help you in your case.
It's not clear if you can execute the c# project or not through mono, if you can, then process intercomunication is the way to go.
If you are doing it in Linux I should use a pipe channeling to intercomunicate both processes, works really well and is easy to use.
If you can't execute the c# process, then that's another history, you cannot call directly a .net assembly from java.
And also, using mono on Linux per today gives great results (except for ASP .net), we are using it and are getting really good results (faster responses than Java in most scenarios).
Is there any way to call the functions which are in a so library from my Java code? Generally, is it possible to use Linux so libraries in Java programs?
The answer is "JNI" :)
Here are a couple of links:
How to compile dynamic library for a JNI application on linux?
http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/
You cannot use arbitrary .so libraries in your Java code. You can use JNI to write a wrapper around native code to access from Java.
However, be aware that doing so negates many of the advantages of using Java. Your code and deployment system now becomes quite fragile and subject to many types of bugs that cannot happen in Java. I would try quite hard to find a pure-Java solution before resorting to using native code.
Another wayto access libraries form java besides JNI is JNA.
I find that in many cases it's easier to use then JNI, but that's just my personal opinion.
So... I will have a project which will be tested on Win 7 and some Linux server. It will be a web service that will use HSQLDB, Hibernate, Spring, Blaze DS and Flash (Flex RIA) as front end. I need to implement into it some image filtering\editing functionality which will be implemented in cross-platform C++ code (It will use Open-CV) wrapped in Java.
I need some kind of tutorial how to create cross-platform Java projects that use C/C++ libs *(most of all I am intrested in crossplatform compiling issue and what IDEs support such things)
It sounds like you'll benefit from the Java Native Interface. If you've got existing C and C++ code that you'd like to use from Java you may want to seriously consider something like GlueGen. It will save you a lot of time generating the code to access your C code.
You can have a look at the official Java JNI Examples here
Something along these lines?
http://www.javaworld.com/javatips/jw-javatip17.html?page=1
You're going to need to use JNI. The Java will be totally cross-platform and can be one project. For C++, you will need to create the JNI callable interface, and build as a dynamic library. The code should be pretty cross platform, but the actual build will be different.
On Linux, you need to build as a .so and you will probably use gcc. On Windows, you will probably use Visual Studio and build a .dll. The build will be different.
I'm wondering if a Java library can be called from a VB.net application.
(A Google search turns up lots of shady answers, but nothing definitive)
No, you can't. Unless you are willing to use some "J#" libraries (which is not nearly the same as Java) or IKVM which is a Java implementation that runs on top of .NET, but as their documentation says:
IKVM.OpenJDK.ClassLibrary.dll: compiled version of the Java class libraries derived from the OpenJDK class library with some parts filled in with code from GNU Classpath and IcedTea, plus some additional IKVM.NET specific code.
So it's not the real deal.
I am author of jni4net, open source intraprocess bridge between JVM and CLR. It's build on top of JNI and PInvoke. No C/C++ code needed. I hope it will help you.
You can call Java from .NET if you wrap it in some form to make it accessable and the easiest way is typically to use a Runtime bridge like
http://www.jnbridge.com/
Other way is to wrap your API with java webservices.
check this also http://www.devx.com/interop/Article/19945
Nothing out of the box.
Most java/.net interop that I know uses web services.
If you can create COM components with Java, you can use tlbimp to create an interop assembly for using in VB.Net.
If can create standard DLLs that can be used from C++ with Java, you can write P/Invoke declarations and call them from VB.Net.
If you can create a web service with Java, you can generate proxy class from the WSDL and call it from VB.Net.
In any case, chances are the Java component will live in a separate process. I doubt you can load both the Java VM and the CLR in the same process.
If you have the source code and compile it using the J# compiler, then the answer is yes. If you want to call any pre-Java 2 (aka 1.2) libraries, then these are included pretty much verbatim with J#. More recent stuff is going to be tricky though (i.e., it's not there).
An example where this is used commercially are the yFiles graph layout algorithms from yWorks. These were originally just a Java library, but for the past few years they've been offering a .NET version, which is just the Java version compiled with Visual J#.
It's not without problems, and there are some limitations that you can't get around, but it can be done. So... unfortunately this answer looks pretty shady as well.
You could use JNI to instantiate a virtual machine and then use Java Classes. It will be some fun, though, because you would need to use C++ as a bridge between VB.Net and Java.
This article in java world has a quick tutorial on how to use Java from C++ and viceversa.
http://www.javaworld.com/javaworld/javatips/jw-javatip17.html
If you have the source, Visual Studio will let you convert Java code into c#.