Importing libraries from build.xml file in Eclipse - java

I am developing a java app and I need to use jnativehook library. I have downloaded the .zip from https://code.google.com/p/jnativehook/downloads/list . There is a bin folder,src folder,build.xml,build.num and 3 .txt files when I extracted this folder.
I have included this library in my project by File -> project -> Java project from existing Ant file
And I have tried an example https://code.google.com/p/jnativehook/wiki/examples
But I get the following error
Exception in thread "main" java.lang.ExceptionInInitializerError
at GlobalKeyListenerExample.main(GlobalKeyListenerExample.java:25)
Caused by: java.lang.RuntimeException: Unable to locate the native library.
at org.jnativehook.GlobalScreen.loadNativeLibrary(GlobalScreen.java:462)
at org.jnativehook.GlobalScreen.<init>(GlobalScreen.java:71)
at org.jnativehook.GlobalScreen.<clinit>(GlobalScreen.java:53)
... 1 more
What location should I give in native library path?

Looking through the source of GlobalScreen.loadNativeLibrary(), it seems that you get this exception when the library has failed to find the DLL on the java.library.path and instead tries to unpack it from the JAR, only to fail to find it.
Some options for fixing this include:
Checking you are running a supported platform.
Extract the right DLL from the JAR and place it on the java.library.path.
To use this library, you only need to include the JAR in your project. I don't like the sound of this part of your question:
I have included this library in my project by File -> project -> Java project from existing Ant file
Just download JNativeHook-1.1.4.zip, extract the ZIP and add the JNativeHook.jar JAR to your project.

Related

Eclipse Referenced Library jar is detected by compiler, but not at run time

I added a jar file to my project by following these steps:
Right click on your project
Select Build Path
Click on Configure Build Path
Click on Libraries and select Add External JARs
Select the jar file from the required folder
Click and Apply and Ok
This imports my jar file just fine, and the Java compiler can detect references to the new library just fine.
When I run the application though, it crashes, saying it doesn't recognize the library:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONObject
at com.ebook.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: org.json.simple.JSONObject
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
What am I doing wrong when importing this jar (json-simple)?
If you have added the jar files properly then you should check in your com.ebook.Main.main(Main.java:14) class whether the related import statement is proper or not.after that clean and rebuild.Hope this will solve your problem.
When you are running the jar file, if you are using library's you need to setup the classpath:
java -cp C:\foo\bar\JsonLibrary.jar your_jar_file.jar
this answer might help you setup your classpath.
Note: The reason why it worked in Eclipse, is because Eclipse automatically handles the classpath for you, but after compiling you need handle it yourself.

Using System.loadLibrary on jar library using windows

I am using a Windows 10 OS and try to get JPBC (Pair-Based Cryptographie) running, as explained here: http://gas.dia.unisa.it/projects/jpbc/buildHowto.html#.WVlWQ4jyhhE . The installation worked well for the libraries and now I am having a bunch of folders, including .jar and .java files in my local maven repo .m2\repository\it\unisa\dia\gas. One of the files is jpbc-pbc for instance but there are more
Now I imported a project from gradle that needs some of those files. This projects includes the line
System.loadLibrary("jpbc-pbc");
Now, this throws an error:
Could not load library jpbc-pbc. JCPABE will be extremely slow.
java.lang.UnsatisfiedLinkError: no jpbc-pbc in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at cpabe.Cpabe.<clinit>(Cpabe.java:24)
at cpabe.demo.DemoForCpabe.main(DemoForCpabe.java:63)
My path variable links to C:\Program Files\Java\jdk1.8.0_131 . Now whatever I try, putting the .jar into it or the src folder or both or whatever, I receive this error.
What am I doing wrong?
Folder structure of jpbc-pbc is
jpbc-pbc
/2.0.0
//jpbc-pbc-2.0.0.jar
/src
//main (and so on)
//test (and so on)
/CMakeLists.txt
/FindGMP.cmake
/FindPBC.cmake
/maven-metadata-local.xml
/pom.xml
The jpbc-pbc library is not in your java.library.path.
Try adding it using:
1. Command Line
java -Djava.library.path=<path_to_dll> <main_class>
2. Source Code
System.setProperty(“java.library.path”, “/path/to/library”);
3. IDE
Depends on the IDE you are using, for example in Eclipse you could:
Right-click on your project in the package explorer
Choose Build Path -> Configure Build Path
Add your library in the Libraries Tab

Jar linking issue in Scala

What i do:
1.I am running a scala project,When i added the java source code(java file) in to the project it run
2.I need to add the jar file the project instead of the java source file
3.So i created jar file for the java source file in eclipse and added the jar file in the scala project instead of the java source file
4.But it shows error,when calling the method in the jar file
5.When i added the jar which i created in the java project,it works
Things i need to know:
1.Is there any different ways to add jar(created in java) in the scala project?
2.Whether i need to create jar in any other way?

java.lang.UnsatisfiedLinkError: no jmtp in java.library.path error while creating .jar file to .exe file using Launch4j software

I am developing a GUI windows app in java.
I need to create an installer now. I got .jar file and now I am creating .exe file using Launch4j free s/w(I hope it is free s/w, Please let me know if it is paid one).
Project has many dependencies of external .jar files and .dll files.
I have included all jar files and dll files into Launch4j s/w when I run it getting the error as "Exception in thread "main" java.lang.UnsatisfiedLinkError: no jmtp in java.library.path"
Please help me how to create a perfect executable file.
Have edited my answer. Below is the working solution.
Add jar to yout project workspace. Here are the steps I followed in eclipse, to add DDL to project.
1.Create a folder under the project, for example dll. 2.Copy/paste all dll files into this folder. 3.In project -> Properties -> Java Build Path -> Source, click and expand the source details. 4.You will see Native library location, click on it. 5.Then click edit on the right, click workspace again. You can see the dll folder under the project. 6.Find it and click Ok. You will see the dll is added in the Native library location.
Post this do the following in run configuration. Say the dll you need is in Y:\path\to\dlls\lib. Then set your Run Configuration's working directory to Y:\path\to\dlls\ and set your VM arguments to include -Djava.library.path=lib
reference: Add .dll to java.library.path in Eclipse/PyDev Jython project

Matlab JavaBuilder jar in Eclipse- missing mkl.dll?

I've been given some jars generated by the Matlab JavaBuilder by some colleagues. Some work fine when I use them in my Eclipse project, but a new one fails with this error:
libmwblas: load error: mkl.dll
And a message about the dll not being found. When I look in the Matlab Compiler Runtime bin folder there is a mkl.dll in there.
Any suggestions as to why Matlab can't or won't see the dll?
Your JARs are using JNI and trying to resolve the required DLL.
Option one is to resolve this is by adding /bin folder you mentioned to your Windows PATH so that Java is able to resolve this (and probably some other) DLLs.
Another (cleaner for development purposes) option is to configure Eclipse by specifying Native library location for the JAR which attempts to load DLLs. Go to Java Build Path of your project, then find the appropriate JAR in Libraries tab, then expand it and set Native library location.

Categories

Resources