jcurses errors while try to import in IntelliJ

275 views Asked by At

I`m trying to import jcurses library to IntelliJ but get an error. File -> Project Structure -> Modules -> import jar file.

Then in code:

import jcurses.widgets.Window;

class main {

public static void main(String[] args){

    Window win = new Window(800, 600, true, "test");
    win.setVisible(true);
}

Exception in thread "main" java.lang.ExceptionInInitializerError
at jcurses.system.InputChar.<clinit>(InputChar.java:25)
at jcurses.widgets.Window.<clinit>(Window.java:209)
at main.main(main.java:7)
Caused by: java.lang.RuntimeException: couldn't find jcurses library
at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:121)
at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)

Could someone point out where is my mistake?

Thanks in advance!

2

There are 2 answers

0
Ronald Coarite On

Libray download url

https://sourceforge.net/projects/javacurses/files/javacurses/0.9.5/

The path of the library is in the root directory of the project

enter image description here

dynamically add the library

import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;

public class LoadLibrary {
    public static void main(String cor[]) throws Exception {
        // Cargando librerias necesarias
        loadLibraryJCourses();
    }
    
    public static void loadLibraryJCourses() throws Exception{
        loadDynamicLibrary(new File("lib/bin/jcourses/").getAbsolutePath(),"libjcurses64");
    }

    private static void addLibraryPath(String pathToAdd) throws Exception {
        final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
        usrPathsField.setAccessible(true);

        //get array of paths
        final String[] paths = (String[]) usrPathsField.get(null);

        //check if the path to add is already present
        for (String path : paths) {
            if (path.equals(pathToAdd)) {
                return;
            }
        }

        //add the new path
        final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
        newPaths[newPaths.length - 1] = pathToAdd;
        usrPathsField.set(null, newPaths);
    }

    private static void loadDynamicLibrary(String pathLibraryDirectory, String libraryName) throws Exception{
        File pathLibraryFile = new File(pathLibraryDirectory);
        addLibraryPath(pathLibraryFile.getAbsolutePath());
        System.loadLibrary(libraryName);
    }
}
0
unitr3ady On

The answer is that dll must be in the same directory as jar file. Thanks to everyone!