Dear friends...
Here i am trying to use openCV in java using NETBEANS(windows XP).., For that i did the following ..
[B]1-Install OpenCV-2.2.0-win32-vs2010.exe in C:\openCV
2-Then i put the javaCV and JNA in the library (System path.)
3-The i use thae following code in the netbeans[/B]
[CODE]
package samplejavacv;
import java.io.;
import static com.googlecode.javacv.jna.cxcore.;
import static com.googlecode.javacv.jna.cv.;
import static com.googlecode.javacv.jna.highgui.;
public class sample {
public static void main(String[] args)throws Exception {
try {
IplImage Iimg=cvLoadImage("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg");
}
catch(Exception f) {
System.out.print(f.getMessage());
}
}
}
[/CODE]
4- But i got the following exception
[CODE]
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:199)
at com.googlecode.javacv.jna.Loader.load(Loader.java:44)
at com.googlecode.javacv.jna.cxcore.<clinit>(cxcore.java:113)
at com.googlecode.javacv.jna.highgui.<clinit>(highgui.java:73)
at samplejavacv.sample.main(sample.java:49)
Java Result: 1
[/CODE]
5-Then what should i do ....please help
6- Remember some site mention that it need to build the openCV , if it need how can i do that please help...
Anyway thanks in advance .....
Happynew year
You will need compiled *.DLL (for 32 or AMD 64 windows platform or *.SO for e.g. linux) files like:
-cv.dll
-cvaux.dll
-cvauxd.dll
-cvd.dll
-cxcore.dll
-cxcored.dll
-cxts.dll
-cxtsd.dll
-highgui.dll
-highguid.dll
-md.dll
-ml.dll
than run your JAVA VM with -Djna.library.path=c:\path\to\your\dlls\directory. E.g.:
java -Djna.library.path=c:\path\to\your\dlls\directory -cp=. Test
Related
I have created a simple java project "DesignPatterns".
I created a file FacadePattern.java with the path being ~/DesignPatterns/Structural/FacadePattern/FacadePattern.java
My FacadePattern.java class,
public class FacadePattern {
public static void main(String args[]) {
// Some code
}
}
But my editor (VSCode) gives me an error at the start of the file:
The declared package "" does not match the expected package "Structural.DecoratorPattern"
So upon clicking on quick fix, it added package Structural.FacadePattern; in the first line.
So the final code became
package Structural.FacadePattern;
public class FacadePattern {
public static void main(String args[]) {
// Some code
}
}
But when I compile the above file using the command
javac FacadePattern.java && java FacadePattern
It is giving me the following error:
Error: Could not find or load main class FacadePattern
Caused by: java.lang.NoClassDefFoundError: Structural/FacadePattern/FacadePattern (wrong name: FacadePattern)
After searching a lot in the internet, I ran the following command:
javac -sourcefile ~/DesignPatterns FacadePattern.java && java FacadePattern
But no use, I am getting the same error.
Can anyone explain why my editor gave an error but code ran successfully before? and why wont it compile after adding "package Structural.FacadePattern;" line? and what is -sourcefile parameter in javac command? and how to run the code with successfully without errors in editor as well as the terminal?
Stick to naming rules. Package names should be lowercase only. In your case, it should be package structural.facadepattern;
Run the 'correct' class. Because your class is not inside 'the base folder' aka the 'default package', you have to prefix the class with its package name: java Structural.FacadePattern.FacadePattern or rather java structural.facadepattern.FacadePattern if you use the proper case for packages.
I'm trying to load a custom made DLL library using java. It takes Input as string and returns output as Integer. I'm using Intellij as IDE.
My code is:
package com.company;
public class Main {
private native Integer IsMalware(String filePath);
public static void main(String[] args) {
System.out.println(new Main().IsMalware("D:\\git.txt"));
}
static {
System.loadLibrary("AMSI");
}
}
File Structure:
Output/Error:
The java version i use is:
[EDIT]
After adding the DLL to library path It shows another error
Can someone help me with this??. Thanks in advance.
I made libcc.so from my test.cpp in ubuntu, and the content of test.cpp is linked with ffmpeg and opencv libraries. After making the libcc.so, it's loaded in JNItest2.java.
JNItest2.java:
public class JNItest2 {
public native void helloworld();
static{
String libPath= "/home/sun/workspace/JNItest2/src";
System.setProperty("java.library.path",libPath);
String Path = System.getProperty("java.library.path");
System.out.println("java.library.path=" + Path);
System.loadLibrary("cc");
}
public static void main(String[] args){
new JNItest2().helloworld();
}
}
However, JNItest2.java can run on Eclipse, the exported jar file can't run in terminal.
Error Message in terminal:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no test 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 JNItest2.<clinit>
(JNItest2.java:23)
Does anyone help me to solve this problem?
Thanks, Hsiu
Take a look here for a sample related to JNI development:
http://jnicookbook.owsiak.org/recipe-No-001/
This is a very simple app where you can take a look at all required elements for running JNI based codes.
In your case:
make sure to put so file in LD_LIBRARY_PATH
if you want to use ffmpeg stuff in your code make sure to check out these two samples as well:
http://jnicookbook.owsiak.org/recipe-No-018/
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo023
I'm doing a processing based project with eclipse and Procliping. When I'm testing the project with "Run" command inside the IDE, everything works fine. But if I export it into a runable-jar, when I run the jar it'll give this error on the line String[] li=Serial.list();. Any idea what's going wrong?
Java source attachment is "processing-2.2.1/modes/java/libraries/serial/src"
And here is a sample code:
package abcd;
import processing.core.PApplet;
import processing.serial.Serial;
public class TestUI extends PApplet {
Serial port;
public void setup(){
System.out.println(Serial.list());
}
public void draw(){
}
public static void main(String _args[]) {
PApplet.main(new String[] { abcd.TestUI.class.getName() });
}
}
My approach of solving it:
Download the latest version of java-simple-serial-connector(Which is the base library used for Processing's serial library), replace jssc.jar in the lib folder, and the error will be gone, and my application runs smoothly.
However the base library is 4 times bigger than the modified version used in Processing, so there may be some unnecessary features involved.
Seems like in their latest alpha version, Processing solved the same problem for exporting apps(at least in windows) by adding more look-up paths, while keeping their Serial library intact. I'm not familiar with their development environment, so I didn't look further into it. There may be a simpler solution.
I'm a java newbie and I'm trying to load a delphi dll, and call functions from it.
Already tried in php using winbinder but it seems to be useless: reloading dll in winbinder (php gui) crashes program
Anyway I have this simple java code, and I can't figure out how to make it work. There are some examples over the internet, but none seems to be working for me.
Dll is 32bit, so is my windows, jdk and Eclipse. Simples function to use would be GetDllVersion. I would really apriciate any help.
I can't even load it, here is first error (there are couple popups following):
Here is the code:
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.*;
public class Main {
static {
try {
System.load("C:/workspace/XmlDownlaoder/xxxxxxxDLL.dll");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
//how to call functions here? - there will be many functions, and final one should generate xml in return
}
}
EDIT: Native code library failed to load - this doesn't show on console.
Don't load your DLL by hand, let JNA do the grunt work for it.
There are quite a few good resources when you search for Delphi JNA.
A few relevant Stack Overflow questions that explain some of the things you will probably bump into:
How can I call a Delphi function that returns a string using JNA?
function mapping delphi/pascal dll in jna handle and string
How would I map this Delphi function with JNA