0

I'm trying to use FANNJ in Eclipse (on Ubuntu), trying to create a toy program but it keeps giving this error as shown below.

Code:

package myPackage;

import com.googlecode.fannj.Fann;

public class mainclass {
   public static void man(String[] args) {
      System.out.println("1");
      Fann fann = new Fann("/home/sahil/Desktop/Intern/Java/eclipse/Workspace/UsingFANN/ANN_Net_Output1.net");
   }
}

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
    at com.googlecode.fannj.Fann.<clinit>(Fann.java:51)
    at myPackage.mainclass.main(mainclass.java:9)
    Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Could someone who works with FANNJ on Ubuntu please explain why this error comes up?

Andre Kampling
  • 5,476
  • 2
  • 20
  • 47
Sahil
  • 1,346
  • 1
  • 12
  • 17
  • Could you copy the error message out as text and paste it here? If someone searches for the error in the future, they'll be able to find this question. – Jørgen R Jun 27 '14 at 07:13

2 Answers2

0

Make sure you set the jna.library.path system property to the path to the FANN Library. This property is similar to java.library.path but only applies to libraries loaded by JNA.

You should also change the appropriate library access environment variable before launching the VM. (LD_LIBRARY_PATH on Linux)

From the command line:

LD_LIBRARY_PATH=/usr/local/lib

java -Djna.library.path=/usr/local/lib -cp fannj-0.6.jar:jna-3.2.2.jar YourClass
Kyle Renfro
  • 1,238
  • 2
  • 12
  • 18
0

You have to download the missing library "jna". After get it you must point it in eclipse (Using the properties of your project > Java Build Path > Libraries, and adding the jar (you can browse it on "Add External JARs...").

A good way to get all dependancies for a project is by "maven". You can simply create a "pom.xml" file on root folder of your project. So write it down:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.something</groupId>
    <artifactId>MyProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MyProject</name>
    <description>MyProject</description>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.fannj/fannj -->
        <dependency>
            <groupId>com.googlecode.fannj</groupId>
            <artifactId>fannj</artifactId>
            <version>0.6</version>
        </dependency>
    </dependencies>
</project>

And finally, on commmand line type # mvn install, it will download the dependancies and by default put all libraries in your "homefolder/.m2". So, browse for JNA library, you gonna find it in some folder like this: "~/.m2/repository/net/java/dev/jna/jna/3.2.7". If your project uses other libraries besides fannj, you can add it in pom file to get everything together.

Cleber Jorge Amaral
  • 1,316
  • 13
  • 26