Convert Java jar file in to cpp - java

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

JPen alternative for Java program

I want to develop a small Java program using some input like the pen of a Wacom graphictablet and found only the very active JPen project but are there some more possible alternatives without JNI or JNA (without any additional needed dll files), a pure Java implementation?
You can take a look at JTablet. From another SO thread.
It seems JPen moved to GitHub and this might be the best solution at the moment.
The other alternative solutions are not developed and maintained anymore.
https://github.com/nicarran/jpen

Dynamically load and run Java code from within Java application

I am thinking about writing a Java application where the user can write some modules in Java and add them to a library in this application. The modules will be some calculations that use data from the main app. Maybe a bit like VBA in Office.
I would appreciate if someone would give me some hints where to start as I couldn't find something useful on the net.
Thanks in advance!
You can try to develop a module framework from scratch, if you wish.
However, if you are developing anything serious you should consider using OSGi.
Theoretically it is possible. You can allow user to write java classes, then you can compile the class using java compiler, generate .class files. you can load them using your custom class loader (probably URLClassLoader or its subclass, etc.
BUT
It is very serious application. Actually it is a kind of IDE. So, of you really want this check out a possibility to create Eclipse based application, i.e. implement several eclipse plugins.
Other approach may be to allow user wring code in one of popular scripting languages. For example groovy that has java-like syntax but can be run without compilation and does not require creating classes etc. Javascript is an option too. Javascript interpreter is a part of JDK, so you even do not need external dependencies.
you might be better off incorporating some form of jvm scripting language. Something like groovy, jruby or jython. Those don't need actual compilation and can be stored in your system as source. Plus they can be quite nice to write code in too. Groovy has the advantage of being a superset of java. (For the most part) you could just degrade to java code, and run it in the groovy interpreter.

Java RMI with Scala, is this possible?

Java RMI -Remote Method Invocation- is Java to Java only.
On the Scala website I read that the integration with Java is seamless and that:
Scala programs run on the Java VM, are byte code compatible with Java so you can make full use of existing Java libraries or existing application code. You can call Scala from Java and you can call Java from Scala, the integration is seamless.
Does this mean that I can successfully use a Java to Scala RMI?
Did anyone experiment this first-hand?
EDIT:
Any known or discovered gotchas??
Yes, here's a link to a message thread where it looks like somebody's done it. It says:
Yes it can! Thanks for help. I now have a little RMI-based pair of Scala programs that will be performing transfers of documents from one Documentum system to another (of a previous version); the Scala code is interacting very nicely with the Documentum Java libraries.
Figuring out how to get the method signatures to include throws RemoteException seems to have been the biggest hurdle.
Yes, this can be done. The rmi compiler works with java byte code, so the language used really doesn't matter. I've done this for a class project.
It would depend on what RMI library you are using but in general, the answer is "Yes." Although, note that if you write a method that returns (for example) a Scala collection like scala.collections.immutable.List, then your calling Java code will probably not be able to convert that to a java.util.List.

Java Wrapper to Perl/Python code

I have to deploy some Web Services on a server that only supports the Java ones, but some of them will be done using perl or python. I want to know if is possible to develop a Java wrapper to call a specific code written in perl or python. So, I want to have all the Web Services in Java, but some of them will call some code using other languages.
Thanks in advance.
Regards,
Ukrania
This depends heavily upon your needs. If Jython is an option for the Python code (it isn't always 100% compatible), then it is probably the best option there. Otherwise, you will need to use Java's Process Builder to call the interpretters directly and return the results on their output stream. This will not be fast (but then again, Jython isn't that fast either, relative to regular Java code), but it is an extremely flexible solution.
For the Python part of it you can use Jython to run Python code right from your Java virtual machine. It'll integrate fully with your Java code as a bonus.
For Perl, use Inline::Java. There are several options for integrating the code; you can call a separate process or you can use an embedded interpreter.
For Python you can use the Java Scripting API.
A Perl implementation is sadly still missing.
There's something I used a while back called Jython which allows you to execute Python code from Java. It was a little quirky, but I got it to do what I needed.
http://www.jython.org

Do you know of a Java library to access the native linux api?

Do you know of a Java library to access the native linux api?
I guess something like this must use JNI. So be it.
Have a look at JNA.
Here is the summary of JNA from their home page.
JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java codeā€”no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation.
See their getting started page for some samples. Like calling native printf.
jtux might help depending on what you want to do.
You can use: Runtime.exec to execute anything you want...
SWIG makes life easier than "raw" JNI with javah etc.

Categories