Eclipse Java OpenCV unsatisfiedLinkError in Test src folder only - java

When loading the library in my main src folder there is no problem, but in the test src folder I get the error. I can still compile and run all the tests normally and they pass.
Both src folder are in the path and I got opencv as a library. Like I said, everything is working, so I guess it's a problem with Eclipse and the display of the error which should not be displayed? So the main problem is that it's visually a pain.
EDIT2 : I just want to say again that everything is working, the tests are all running, it is simply that they pop as problems (and I don't see the errors of the tests because this unspecifiedlinkerror is before and overshadow them)
Also, it does the same thing on both my Windows and Ubuntu machine.
my path is also correct when I print it out right before the System.loadLibrary as .../opencv-2.4.11/build/lib
EDIT3 : I tried Cibin William answer and put my .dll path but to no avail

You can right on the project and click on Build Path -> Configure Build Path -> then select the Libraries tab and select OpenCV jar file and then expend it and then select on Native Library Location and then click on the Edit and then brows the to the .dll file of OpenCV something like this C:\opencv\build\java\x64 Or C:\opencv\build\java\x86 for 32bit System. And it is that.
Or You can load the library by coding (dynamically)
public static void loadOpenCV_Lib() throws Exception {
// get the model
String model = System.getProperty("sun.arch.data.model");
// the path the .dll lib location
String libraryPath = "C:/opencv/build/java/x86/";
// check if system is 64 or 32
if(model.equals("64")) {
libraryPath = "C:/opencv/build/java/x64/";
}
// set the path
System.setProperty("java.library.path", libraryPath);
Field sysPath = ClassLoader.class.getDeclaredField("sys_paths");
sysPath.setAccessible(true);
sysPath.set(null, null);
// load the lib
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

When I run the OpenCV program in eclipse ,unsatisfiedLInkError occurs.I solve the error by exporting the library path in eclipse as follows
1.Right click on the project,seleect Debug as->Debug Configurations...
2.Debug Configuration window appears,Select the Environment tab in the top
3.Click the New button on the right side of the window,A New Environment Variable window appears
4.On the Name type LD_LIBRARY_PATH and in the Value type the folder which contain the .dll file(If the .dll is present in the Lib folder inside the project,type Lib in the Value)
Please try and reply.....

Well, I reinstalled Eclipse and that did it...sigh
The bug was on both Eclipse Luna and Mars Version 4.5.1.
Mars Version 4.5.2 is working fine.

Related

Main.java is not on the classpath of project NewProject_880753af, only syntax errors are reported - Java(32)

Yesterday I opened VS Code after a month or so, and I noticed, that all my projects' Java files can't run. I see a light blue curved underline under the first letter in all my Java files, which says:
Main.java is not on the classpath of project NewProject_880753af, only syntax errors are reported - Java(32)
I have my Java file inside "src" directory inside my project directory "NewProject".
When I try to run my file, it then prompts me to add the parent folder to some Java source path:
The file Main.java isn't on the classpath, the runtime may throw class not found error. Do you want to add the parent folder "NewProject/src" to Java source path?
Then it gives me two options - "Add to Source Path" or "Skip". If I press "Skip", it shows an error again:
Cannot resolve the modulepaths/classpaths automatically, please specify the value in the launch.json.
If I choose "Add to Source Path", then it creates a folder called ".vscode" with a file "settings.json" in which there's the following code:
{
"java.project.sourcePaths": [
"src"
]
}
And after that it works... but... I just don't understand - why did Visual Studio Code fail to run my file even if it was working everytime I ran it in the past and without any prompts to add my parent folder to source path or anything?? And I didn't need any "launch.json" files!
How can I fix this problem without creating any new folders inside my project directory?

Java .dll files not working in .jar

I'm trying to listen keyboard events in Java by using a third-party library from "net.java.games.input". When I run my code in Eclipse, it works fine. But when I build my project and run the .jar, it does not. The reason I guess, the library needs some .dll files to listen my keyboard and they don't work in .jar.
Here's my code example;
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] ca = ce.getControllers();
So, what should I do to make this work in a .jar?
Thanks.
You can use System.loadLibrary() to let the JVM loading your dll or System.load() to load file from a specific path:
static {
System.load("PATH/TO/file.dll");
}
so your issue is relative to this
JInput "no jinput-dx8 in java.library.path" Error
You should set java.library.path property to point to the directory
containing native dlls of JInput. You can do it by adding
-Djava.library.path=x (where x is your path) to the command line or to the "VM arguments" field of "Run configurations" dialog in Eclipse.
answered Jan 12 '10 at 19:48
axtavt 198k31421427
you can also at the beginnning of your main do this
System.setProperty("java.library.path", System.getProperty("java.library.path")+";thePathOfYourDll");

how can I make a jar file in opencv project elclipse?

I am running my OpenCV project in eclipse successfully. I have added OpenCV-3.0.0 as my user library in my projects,but when I export a runnable jar file it can't be running in cmd windows (while the jar file of non-opencv projects run in cmd successfully). the [image below shows the error in running time of the jar file
I will be grateful for your guides.
You need to load the OpenCV lib pragmatically, you can try this:
public static void loadOpenCV_Lib() throws Exception {
// get the model
String model = System.getProperty("sun.arch.data.model");
// the path the .dll lib location
String libraryPath = "C:/opencv/build/java/x86/";
// check for if system is 64 or 32
if(model.equals("64")) {
libraryPath = "C:/opencv/build/java/x64/";
}
// set the path
System.setProperty("java.library.path", libraryPath);
Field sysPath = ClassLoader.class.getDeclaredField("sys_paths");
sysPath.setAccessible(true);
sysPath.set(null, null);
// load the lib
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
Now when your program initiated, you call the method at the first, then it will work.
Hope it solves the problem!
I have solved the problem by copying the opencv_java300.dll file in the folder D:\OpenCV3.0.0\opencv\build\java\x86 to the folder c:\windows\system32.

Runnable jar exported with eclipse isn't working, in eclipse it still works

I'm trying to export a java project in eclipse as a runnable jar, but for some reason the runnable jar doesn't work. If I double click the executable jar, it doesn't do anything. I tried both extract and package required libraries into generated jar.
So I also tried to export some simpler projects, those worked fine. The biggest difference is my real project has files: images and xml files.
In code reference them like this:
File file = new File("Recources/test.xml");
ImageIcon imageIcon = new ImageIcon("Recources/" + num + ".gif");
The structure of the project looks like this:
But in the executable jar they look like this:
Thank you for your help.
Edit:
I have tried the 'java -jar filename.jar', but now it says it can't find my resources folder, while in eclipse it can still find it.
Files in a JAR-File aren't just like files stored in your hard-disc. If you include files in a JAR, they'll be seen as a Stream of Bytes. So you have to use different methods to access these resources.
//To read/access your XML-File
BufferedReader read = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/test.xml")));
//To read/access your gif-Files
ImageIcon icon = new ImageIcon(this.getClass().getResource("/"+num+".gif"));
"/" is not the root-Folder of your file-system, but the root folder of the resources inside your JAR.
The issue may be that Java is not the default program to run the jar.
Try right click -> Open with, and select the Java Runtime, and it should run successfully.
Make it the default program to enable double-click running.
Right click -> Properties -> Change -> C:\Program Files\Java\jre7\bin\javaw.exe
Inspired by stratwine's answer at https://stackoverflow.com/a/8511277
So thank you all, but it seems like the problem wasn't the export only. There was an error I saw when I opened my program with cmd, I was using file name to open xml and images while I should have used inputStreams: https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html.

Error in COMM API Installation: nblibraries.properties file doesn't exist

I'm trying to run this sample code which is querying available com ports from here: http://www.java2s.com/Code/Java/Development-Class/QueryingAvailableCOMPorts.htm
// Install the Java Comm API first. if there is no necessary file, say Dll files, the API
// won't work.
import java.util.Enumeration;
import javax.comm.*;
import java.util.Enumeration;
public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
}
}
I added comm api properly into my project, i can see my comm.jar file under Libraries folder of my project. But when i build the project, netbeans gives me this message:
ant -f C:\Users\Timur\Documents\NetBeansProjects\KEYCON clean jar
C:\Users\Timur\Documents\NetBeansProjects\KEYCON\nbproject\build-impl.xml:63:
Source resource does not exist:
C:\Users\Timur\Desktop\javax.comm\nblibraries.properties BUILD FAILED
(total time: 0 seconds)
And when i try to run project, Netbeans gives this message:
run: Error loading win32com: java.lang.UnsatisfiedLinkError: no
win32com in java.library.path BUILD SUCCESSFUL (total time: 0 seconds)
Should i store my comm.jar file somewhere specifically? It's in my desktop now. Or does the problem occurs because of something else?
Another question of mine which wasn't answered by this community :/
And again i have write answer by my own. so here it is:
but the thing is what i write here is generally the same solution for similar questions on this site or other sites and yet i didn't work out at first 8-9 times.
For the jdk (Java Developnment Kit) to recognize the serial ports on
your machine, it is important to properly place these files in the
right folders on your local machine :
%Java_HOME% = the location of your jdk directory.
To Find your JDK directory, Use the Following steps:
Click on Start
Click on Search
Click on For Files or Folders …
In the Left hand Side, Click on All Files and Folders
Type in jdk* in the textbox under All or part of the file name:
Click Search
Look for yellow icon that looks like a folder
Double Clikc on the folder to open the jdk folder
comm.jar should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib/ext win32com.dll should be placed in:
%JAVA_HOME%/bin
%JAVA_HOME%/jre/bin
%windir%System32 javax.comm.properties should be placed in:
%JAVA_HOME%/lib
%JAVA_HOME%/jre/lib
One of the reason, this issue can occur when you have installed fresh Netbeans and open a project having reference to a custom library.
I had same issue and I resolve by just creating a custome library
Create Library
Select Tools > Libraries to open up the Library Manager.
Click the button Add JAR/Folder and browse to the lib folder within the ImageGear for Java installation directory. Select all *.
Click Add JAR/Folder to accept the JAR files you have selected. Then in the Library Manager, click OK to exit.
it will create the nblibraries.properties file and issue will be resolved. now you have to provide reference .jars only
Note: you may have different problem, but if problem is same like me you can try this method.

Categories

Resources