Open Sam-Lee-17 opened 6 years ago
I am not sure what the issue is, but you should look around for help on adding native libraries to the IDE, extract the library you need from the jar. The only thing that cause the demo to run is the execution of the jar via its manifest. I suspect you may have borked something in the class path of the jar.
So I think I am having a similar problem and may be able to explain the problem a little better (or at least the problem that I am having). I have added the libraries and can run the GlobalMouseListenerExample. Now I want to make an instance of the GlobalMouseListenerExample for use in a separate main class. but when I throw in a statement like GlobalMouseListenerExample exD = new GlobalMouseListenerExample() into the constructor of the class that is called from my main, all of the other components in the constructor don't do anything and the program runs as if GlobalMouseListenerExample was the only class in the project. I am certainly way out of my depth on this one, but I feel like Sam and I are making a similar mistake. Could this be a problem with the event Que?
I got the same problem. When I execute the .jar file, it runs the demo. Any idea what is happening? I don't know what to do
I am gong to need a sample project so I can see this problem in action if there is any hope of me providing an answer. I simply don't understand what you are doing. Something is clearly blocking when GlobalScreen.registerNativeHook(); is called but that isn't how this library works by default.
When the hooks is registered it does indeed block execution, but that blocking should be happening in the NativeHookThread thread. Somehow you have created a thread safety issue but I'm not understanding how based you what has been said.
Create a very basic project structure that illustrates this problem, zip it up and post it here.
@Franco940 This seems to be working normally for me... what problem are you having? What OS are you using?
@Franco940 This seems to be working normally for me... what problem are you having? What OS are you using?
I'm using windows 10 Pro
When I run the program in IntelliJ, run normally. But when i make the .jar and i execute it, run the native hook demo
send me the jar, or at least the manifest. Also how are you running the jar?
I found a solution. When I execute the .jar with this command: java -jar file.jar, runs demo. But if I execute the .jar like: java -jar cp file.jar org.example.Main, runs well
The manifest only contains:
Manifest-Version: 1.0 Main-Class: org.example.Main
When I execute the .jar with this command: java -jar file.jar, runs demo. But if I execute the .jar like: java -jar cp file.jar org.example.Main, runs well
This doesn't make sense. There should be two jar files: One jar for your project, one jar for this library. You should be executing the jar file with something like java -cp jnativehook.jar -jar yourproject.jar
How are you only ending up with 1 jar file... how is that single jar file running the native hook demo? How does it contain native hook code?
Are you trying to bundle both projects together?
This is completely unsupported and volatiles the license of this project unless your project is GPL.
Based on the last comment I have been researching and learning. Now it works correctly
Thank you so much. Sorry if I have wasted your time
I'm sorry if this is a stupid question but whenever I compile my application in IntelliJ and run the jar file it runs the Demo application but not my code even with my main file being specified as the main target. I have spent ages looking around but just can't see anything to do with this. I was wondering if there is a specific way my program needs compiling or if there's something I need to add on top of just the JNativeHook library. Again apologies if this is a stupid question but thanks for your help.