For my program i need to register key events that happen without the application having the focus. (i.e. internet explorer having the focus) I have been looking and people say you can do it with jni; however, is there anyway to do it without it?
Can someone give me a link of a really good jni example? the ones i have looked at so far havent been very helpful
JIntellitype (which is an Apache 2.0 license) will do this for you in Windows. JxGrabKey appears to be a valid solution for Linux. I'm not aware of a cross-platform solution. (These still use JNI, but they'll abstract the details for you)
http://melloware.com/products/jintellitype/index.html
http://sourceforge.net/projects/jxgrabkey/
Do you want to create a key logger? No, it is not possible without JNI or using some library which wraps the JNI away for you.
The only way in Java to do things outside of your own Frames/Windows is using java.awt.Robot, but this only allows screenshots and sending input to other programs, not capturing input.
Related
Is it somehow possible to write active-x component on Java?
Any library, tutorial and samples will be helpful
Thank you
The closest you'll get to it is the Java-ActiveX bridge:
http://download.oracle.com/javase/1.4.2/docs/guide/beans/axbridge/developerguide/index.html
I would be careful with using EZJCom since it can be a source of many memory-leaks (at least as of version 1.8). The native code in this library often creates global JNI references to Java objects. Some of the references are never removed which pins down the object forever and prevents it from being garbage collected. I've seen a lot of such cases, eg. COM event listeners, ActiveXObjectContainers and sometimes even pure Java event listeners that were added to ActiveXObjectContainer.
Although I reported the issue to developer, the feedback I got was far from satisfactory, ie. I didn't get any resolution. Because of this I had to make ugly workarounds on Java-side to mitigate the problem.
You probably look for Java COM Bridge:
Build a COM/ActiveX component for Java classes in 15 minutes
and
There are two directions using EZ JCom: Java to COM, and COM to Java [...] You give it Java classes and pick some methods and fields, and it will give you a COM component that can be easily used by VB, C# or C++.
Note that I couldn't find an example for "build COM components" :-/
If you want to integrate it into a web page this is called a Java applet (sorry the Java applets website seems to be down right now). Otherwise you should maybe look at the Java Plug-in Technology page.
I need to get control over Windows of WindowsXP using Java code,
I need to click/type on particular button/textfield of given window of windowsXP,
How to do this any idea?
Approaches I tried are:
(1) I Tried AutoIT framework, but its Java Wrapper is buggy.. not stable.
(2) JNA can be used for native interfacing, by using some .dll file
to achieve the same. But I don't know which .dll file is used by windowsXP.
Can anybody elaborate on this?
I've not much idea which is much better solution.
Is there any better framework available for such thing.
Thanks.
WindowsXP uses multiple dll files, not one, and studying its API will tell you which one has which functions, and then you can use this information in your JNA interaction code. BTW, I have use AutoIt by itself to help do what you're trying to do and it works fine, and is easier than Java with JNA since it's built for this sort of thing. I've also used AutoIt with Java by having Java call small AutoIt programs and get some simple interaction via standard input and output streams taking care though of the tips and traps in this great article: When Runtime.exec() won't
Thinking outside of the box here...
What possible basic approaches could be taken in an effort to create a Flex component that could run Java?
I know I can easily use flex to browse to or launch a Java app, but there are things I can only do if I can run the Java from WITHIN an MXML Component.
I the strictest sense, I know it's not impossible (ie: if you had all the source code for flex and for the jvm), but what's the least impractical means to this end?
Edit:
Lots of people are interested in the reason WHY someone might want to do this. I see it as irrelevant to HOW to do it, but here goes: I have over 100 proprietary pixel-reading windows programs that I could port to Mac in this way, much easier than any other way. But instead of arguing the premises, the winning answer will ignore the reasons why, and focus on the HOW.
Showcase your creativity.
This sounds crazy insane to me. My answer is to not go down this route. It may be a fun technical challenge for fun; but has little practical value that I can see.
Answer the question, Why would you want to run a JVM inside a Flex app?
Also, How would you use a Flex App to browse or launch a Java App? As best I understood, the security sandbox of the browser prevents you from launching other local applications.
I don't believe you are correct about not being able to accomplish certain things you "can only do if I can run the Java from WITHIN an MXML Component". With proper communication set up, you can have the Applet and the SWF simply communicating with each other through an external set of processes.
The easiest way to accomplish this is to "fake it". Load a Java Applet (This should be possible by use of the SWF's ExternalInterface API -- generate the Object tag and add it to the HTML around the swf. To make this even more convincing, use CSS to have to Applet appear "on top" of the swf. ) and have it communicate with the original swf through JavaScript calls. If that is not possible, then it may be possible to have the Java Applet generate some form of pseudo-server which the swf could then communicate with.
If neither of those work, then there is always the SWF bytearray syntax. It would need to load a ByteArray, manipulate the internal data, and then send it... somehow.
A while back I prototyped something like this. I exposed a window / native app via a VNC server and then used an open source VNC client library to connect to the VNC server. It was totally hacky but it worked. Performance was not great but was usable. Here is the Flash VNC client library I used:
http://www.wizhelp.com/flashlight-vnc/index.html
I'm with Flextras, you need to explain why before a reasonable solution can be proposed.
Unreasonable solution:
Implement the jvm in AS3. Read jars in as bytearrays. Pass the bytearrays to you new jvm.
Reasons for unreasonableness:
Implementing even a partial jvm would be at least thousands of man hours of work.
Running a virtual machine inside of Flash's already (relatively) slow vm would be like riding a golf cart that's being towed by a tortoise: either one by itself would be faster.
You can interface between Air & a Java app using merapi (although that's just communication, not actually running the api inside air)
Assume I have a webpage where people submit java source code (a simple class).
I want to compile and run the code on my server, but naturally I want to prevent people from harming my server, so how do I disable java.io.* and other functions/libraries of my choice?
A regexp on the source code would be one way, but it would be "nicer" if one could pass some argument to javac or java.
(This could be useful when creating an AI competition or something where one implements a single class, but I want to prevent tampering with the java environment.)
If you are in complete control of the JVM, then you can use security policies to do this. It's the same approach taken by web browsers when they host applets.
http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html
Hope this helps.
Depending on your intent, you might be able to speak with Nick Parlante, who runs javabat.com - it does pretty much exactly what you're describing. I don't know whether he's willing to share his solution, but he might be able to give you some specific help.
My advice is don't do it. At least, don't do it unless you are willing and prepared to accept the consequences of the machine that runs your server being hacked. And maybe other machines on the same network.
The Google App Engine uses an approach where classes are white listed - that is, they are probably either not loaded, or the classes themselves changed and the libraries recompiled, so that no IO, or other system calls can be made. perhaps you could try this by recompiling a jvm like http://jikesrvm.org/.
You can always run the code in a custom classloader. This allows you full control about what you will accept to load.
My goal is to get Limewire(JAVA) and Songbird(XULRunner) to run together.
I was thinking the best way is to run the XUL application(songbird) inside a JAVA swing panel. Is there another way?
Would it be better or possible to have the GUI entirely in XUL, and then access my JAVA objects somehow?
How would I go about doing this?
Thanks
Take a look at JRex, as it might let you peek into a couple of ideas.
Other than that, I'd also research about Rhinohide as well.
Take a look at DJ Native Swing, a native Swing implementation using SWT and Xulrunner.
I am currently researching XUL for a new product and I came across JavaXPCOM which allows Java code to interact with XPCOM objects. I'm still wrapping my head around the Mozilla stack, but from what I understand all XULRunner applications use XPCOM. Therefore, it seems like you should be able to embed Songbird with this approach.
The official XUL implementation by Mozilla and is heavily dependent on Gecko.
Gecko is not written in Java nor embedded in AWT/Swing/SWT (at least without using JNI).
So, the short answer is: no. You must either use JNI or use heavy, complex and incomplete third party libaries.
However, JavaXPCOM seems to allow embedding Gecko: https://developer.mozilla.org/en/JavaXPCOM
But in that case you'll depend on Gecko... and I don't know if that's enough to run Songbird.
I would examine Limewire's source code. If there's a clean separation between UI and the rest of the application, I would try finding a solution to instantiate and invoke Limewire's non-UI code from within a Songbird extension.
I would take a look at eclipse swt's embedding of
xulrunner:
http://www.eclipse.org/swt/faq.php#whatisbrowser