Unsatisfied Link error (loading DLL using Java) - java

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.

Related

Error compiling simple Java File: ClassNotFoundException

What can be the problem when I'm compiling Tareena.java file in my C:/FindTheWallet/Proj/ folder? I am getting ClassNotFoundException.
Here is my code below:
class Tareena
{
public static void main(String args[])
{
System.out.println("Still working on it ? ");
}
}
The reason for your problem is Tareena.class is not in your classpath when you are running your program. Follow this link
Compile your class first using javac Tareena.java and then execute it using java Tareena

How to enter a relative URL when linking to an access database

I'm doing a Java project for school where we have to use MS Access to store the data. I've managed to get the database up and running, however i can't seem to find how to make the link to the database relative. I've searched the web and tried everything I can think of but nothing seems to work. Anybody here that can help?
Here's how I've put the link now:
private static final String DATABASE_URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\Users\\Badlapje\\Dropbox\\workspace\\FOOP\\Group62RISK\\Risk.accdb";
Which I then invoke as follows:
connection = DriverManager.getConnection(DATABASE_URL);
What I want to do is make the link relative, so all members of our team can use the same link.
The problem is in the access database file location: C:\\Users\\Badlapje\\Dropbox\\workspace\\FOOP\\Group62RISK\\Risk.accdb. Just make sure to place this file in a folder that everyone has in its computer like C:\\school-project\\Risk.accdb.
Another solution could be to set your file inside your Java project inside a source package and then load the file absolute path using Java code (adapted from this answer):
package edu.proj.res;
public class Main {
public static String getDatabaseLocation() {
return Main.class.getClassLoader().getResource("edu/proj/res/database.txt").toString();
}
public static String changeToWindowsPath(String path) {
return path.replace("file:/", "").replaceAll("/", "\\\\");
}
public static void main(String[] args) {
System.out.println(changeToWindowsPath(getDatabaseLocation()));
}
}
Having a project structure:
ConsoleTests
- src
- edu.proj.res
+ database.txt
+ Main.java
Program output:
C:\workspace\ConsoleTests\bin\edu\proj\res\database.txt

how to find shared library path in java without using LD_LIBRARY_PATH

I want to load so file "libhello.so" with java, for some reasons, i can't change LD_LIBRARY_PATH in redhat, the .so file "libhello.so" is in /home/arthur/lib, how can i load this so file? below is the sample code:
class HelloWorld {
public static void main(String[] args) {
System.loadLibrary("hello");
}
}
Try this way:
System.load("/home/arthur/lib/libhello.so");

fannj library doesn't work

I'm trying to run project which uses fannj library, but I'm getting error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'fann_create_standard_array':
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:347)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:327)
at com.sun.jna.Native.register(Native.java:1355)
at com.sun.jna.Native.register(Native.java:1032)
at com.googlecode.fannj.Fann.<clinit>(Fann.java:46)
at javaapplication9.JavaApplication9.main(JavaApplication9.java:14)
Java Result: 1
This is what I did:
I put fannfloat.dll to C:\Windows\System32
I added fannj-0.3.jar to project
I added newest jna.jar to project
here is code:
public static void main(String[] args) {
System.setProperty("jna.library.path", "C:\\Windows\\System32");
System.loadLibrary("fannfloat");
Fann fann=new Fann("D:\\SunSpots.net");
fann.close();
}
SunSpots.net is file from example package. fannfloat.dll: you can get from here.
The "#8" at the end of _fann_create_standard_array indicates that the library is using the stdcall calling convention, so your library interface needs to implement that interface (StdCallLibrary) and it will automatically get the function name mapper applied that converts your simple java name to the decorated stdcall one.
This is covered in the JNA documentation.
It was the first time I had to work with FANN and it took me some time to make it work.
Downloaded Fann 2.2.0. Extract (in my case "C:/FANN-2.2.0-Source") and check the path of the fannfloat.dll file. This is the library that we will use later.
Download fannj-0.6.jar from http://code.google.com/p/fannj/downloads/list.
The dll is compiled for 32 bit environment. So, make sure you have a 32 bit Java installed (even in 64 bit Windows).
I suppose you already have the .net file with your ANN. Write something like this in Java
public class FannTest {
public static void main(String[] args) {
System.setProperty("jna.library.path", "C:/FANN-2.2.0-Source/bin");
Fann fann = new Fann("C:/MySunSpots.net" );
float[] inputs = new float[]{0.686470295f, 0.749375936f, 0.555167249f, 0.816774838f, 0.767848228f, 0.60908637f};
float[] outputs = fann.run( inputs );
fann.close();
for (float f : outputs) {
System.out.print(f + ",");
}
}
}

javaCV in NETBEANS on windowsXP platform

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

Categories