i have a php library which is in php. can i have this lib to work in java environment like calling the functionalists of the lib to work exactly like a java lib?
Regards
Tony
Short answer: No
Long answer: No, you can't... They are two completely different languages.
Java runs on the JRE as a platform. The PHP interpreter run natively on the OS on which it runs.
The best you could do is run PHP as a system process passing the PHP file you want to run as an argument, and capture that process' output. (ie: run "/path/to/php myfile.php", and read the output).
However, I should warn you that this is a horribe idea, and you should really re-think what you're doing. You java code will loose it's portability completely, as well as become awfully designed.
Related
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).
I'm building a cross-platform Java project that has to reference some python2.7 scripts. Jython seems perfect for this, but there are a couple problems: the python script uses M2Crypto. Is there any way to include M2Crypto into Jython in a way that's natively cross platform and doesn't require installing any extra programs?
EDIT:
To be specific, this is the file that's giving me problems:
https://raw.github.com/GotoHack/pymobiledevice/master/ca.py
This won't work ... M2Crypto is a binding to the C library openssl. Unless you do some really wild gymnastics with JNI there is no way how to make this code work directly with Jython. OTOH, you don’t have to, Java has just fine bindings to crypto libraries on its own. Use that.
I'm not completely sure but there is not. M2Crypto requires external installation that might differ from system to system. For example if you want to install it on Mac OS X it's not very easy (but not hard as well), on Linux (Ubuntu) is a bit easier. So you might need to right a script that installs it on you system automatically.
I have written python scripts that use scrapy,nltk and simplejson in my project but i need to run them from java as my mentor wants to deploy them on a server and i have very less time to do this.I took a glance at runtime.exec() in java and jython, needless to say that running system commands from java doesn't look simple either.
So I would like to know if running the python scripts from java as system command -'python example.py ' using runtime.exec() or alternatively using jython would be more simpler and actually feasible or whether there is a simpler workaround .It would also be great to know if anyone had run python code that uses nltk from java using Jython and whether they encountered any problems.Please help me as I have to do this as asap.Any thoughts and suggestions regarding this are welcome.
Thanking in advance!!
The Jepp project lets you call python scripts from Java. It provides an easy mechanism to pass variables into a script and extract values back. I've used on a few projects with good success
I have a Java app that takes a long time to be initialized (so I can't use a command-line like interface) and I need to pass text and receive the output of a Java method from Python. Is it possible to load the Java application, have it open all the time the Python script runs and use a method from that app?
I don't think the use of Python helps all that much over a command line (at least not a *nix command line), but the basic idea is to communicate over a socket or some similar mechanism. That means that the Java application will have to be wrapped in some code which opens a socket and waits for the python script to contact it. If you are most comfortable with python, you could look to implement that wrapper in Jython.
I've used JPype for something similar and it worked great.
JPype is an effort to allow python programs full access to java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both Virtual Machines.
If the java app is running you should also consider xml-rpc as it also works well.
Py4J is a way to call Java from a python script. Here is the project website: http://py4j.sourceforge.net/
Want to create animation dll for Window XP
Is it ok to create Java2d animation and export as dll??
Yes. You need to write code in C++ to start the JVM with the invocation interface to JNI, and call into it. However, you may find it difficult to create windows in this way that integrate seamlessly with your Windows environment application to display your animation. This is a rather advanced JNI usage, and I'd recommend reading the JNI book before even trying a little bit of it.
I am pretty sure you can only create .Jar files from java not dlls
I doubt so, unless there's some 3rd party tools out there. For your case where graphics is involved, chances are even lower.
Actually, what Quentin said should work. When you compile java to native with GCJ you first compile the .java files into platform specific .o (object) files. Presumably you would compile the .o files into a dll rather than an exe. GCJ also includes components like the garbage collector, and base java libraries. None of which require a JVM to run. The downer is that the dll would be huge. A simple "Hello World" app when compiled with GCJ is ~35MB, thanks to all the default libs and the garbage collector. Likewise your dll would be huge.
There are "bridges" that allow Java and non-Java code to call into one another. Depending on what you are trying to accomplish, these might be useful as you could write your Java code and then call into it from a C++ or C# DLL, depending on which language you are creating your DLL with, which will also determine what kind of bridge you need. I have never seen a freely provided bridge though. All the ones I've found when looking had to be purchased.
No, IIRC you can't. DLLs are linked directly when loaded. Java code needs a jvm, so you can only provide a dll that starts a jvm and starts code there, but not all necessarily stuff fits in the dll.
You should not do this. It looks like you're trying to use the wrong approach for your problem.
Well…
GCJ is available for Windows.
GCJ is part of GCC.
GCC can create dlls.
It might be possible to put that together to build DLLs using GCJ.
Yes, it is possible to generate DLLs from Java source code.
2 Methods I have used:
IKVM
Graal
IKVM is mature, but rather slow in runtime execution of the generated DLL.
Graal is fast, but early days and immature in the Windows environment.
See https://openjdk.java.net/jeps/295 for further info.
There are other commercial options available as well.
I agree with bmargulies. It's probably feasible for an expert, but it would be a large DLL and you'd be mixing technologies that were never made to work together. It doesn't make sense to try this, in my opinion.