Reference M2Crypto from within Jython - java

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.

Related

How to make a PHP library work in java environment?

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.

Use VBoxManage from code or libvirt?

I am currently doing a project that needs VirtualBox as third party software. It doesn't need to do very complex stuff, basicly just import an .ova, forward a port, start it, export it again and some cleanup (never more than 1 vm at the time).
This will all be written in Java and needs to work in both linux and windows. My question is, what do you guys think is a better approach? Right now I'm just using the VBoxManage application (which is also exactly the same on both platforms), which means that I can use exactly the same code without any libraries in windows and linux, the only thing that's different is the binary path.
On the other hand, if something in the VBoxManage syntax changes that means it has to be updated and libvirt probably fixes this for you in an easier way.
Point is, I'm not sure what to do, libvirt seems awfully complex and big for something as simple as this and the library itself is also not platform independent =\. Any suggestions?
I will stick with VboxManage. Even when the command syntax changes, it is simpler to manage.
Using libvirt may mean using JNI and more code and more maintenance.

Is it possible to use Java to create dll?

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.

Best way to create a standalone program for windows without having to install pre-requisites?

I've been charged with creating a little GUI launcher app to go on a CD which will offer the user some software and some videos. It's not being aimed at particularly tech-savvy people, so it needs to be quite simple. I guess the real sticking point here is that it will be form based.
I would very much like the launcher to just run from an exe without having to install any .net stuff or have java installed. I know ClickOnce is fairly simple and I will fall back on it if necessary, but I thought it might be worth asking if there are any easy ways to do this.
I mainly program using visual c# these days, but have experience with java and c and I am a relatively quick learner, so feel free to suggest other languages.
The most straightforward way to create a dependency-free executable for Windows is to use ordinary Win32 functions from C (or C++). Alternatively, you could use MFC with C++ because you can link MFC right into your executable to avoid a dependency on MFC DLLs.
There are probably other C/C++ frameworks that can be linked into an executable. However, you probably want to avoid Java and C# or any other .Net language, if you want minimal dependencies.
Depending on the minimum target OS, you could possibly choose VB6, if it doesn't affend you too much, because the VB6 runtime has been included in windows since Windows 2000. However, you need to stick to the included controls to keep things simple.
If you write it in Java you could bundle the JRE on the CD and just have a batch file that uses that bundled JRE to launch the app. This should work, but the JRE is kind of large, so you'd need to make sure you'll have enough space on the CD for it.
.Net might be able to do something similar but I've never looked into it at all.
The simplest thing would probably be to just write a simple native app in C/C++ (or in some other language that compiles to a standalone EXE) and use that.
Just statically link to the C runtime library and any others you might need (like MFC): /MT or /MTd on the command line and Project Properties > C/C++ > Code Generation > Runtime Libraries in Visual Studio.
You can use C++ with wxwidgets for GUI and statically link your application
Now all the windows OS (from win 2003) pre installed with .Net frameworks... so you can go ahead and code in any CLR language...
You are saying ur clienats are not tech ppl, so the chances for uninstalling .net frameworks from their machine is very low..

How can I retrieve a hard disk's unique ID using Java+JNI on Linux, Windows and Mac

How can I retrieve a hard disk's unique ID using Java+JNI on Linux, Windows and Mac?
To sum it up: you can't do this with just Java
I do not think there is a simple, uniform way to do that.
You can however create seperate logic for all cases; on linux you could check /proc (using the java.io package). There are probably similar ways on OS X and Windows, or, if not, you could execute a shell script or batch file on these systems and parse the output.
Or you could use JNI, though that would mean building your module for all environments.
You could use Java+JNA (https://github.com/twall/jna/), but then you'd have to figure out how to gather that information by using native libraries on each of the platforms you'd like to support.
The benefit is that you wouldn't have to compile any C/C++ code for each of the platforms. If you decide to go with that option someone else might be able to tell you how to figure out the harddisk IDs on the different platforms using C/C++ code/libraries.
AFAIK, on Linux you need to read something from /proc or /sys, on Windows I would look through MSDN and see what you could find that is usable in Visual Studio (C++) and for Mac someone else would have to fill in. Solaris/BSD should probably be supported too if you do it right. In fact, for most of the POSIX-compatible OSes out there I think you should be able to do it somewhat uniformly.
As already in indicated, you can't within the boundaries of the question. However, you might be able to do it with a combination of java and native code specific for each platform via the JNI layer.
I may be wrong, imho, this canNot be done without using JNI.
Build your app in two parts
Native component that will use either a script/application to query the hardware, and output to a file
Your java app to read from the file and do whatever

Categories

Resources