loading library from jar, classpath...

Hi

I’m not new to programming but some things in java I don’t understand until know.

I’m programming at Linux Debian Lenny 64Bit.

The first thing: I got the JInput class as .jar file
I createt a class with the code from http://www.java-gaming.org/index.php/topic,16866.0.html
when i compile the class I got an error.


test.java:5: cannot find symbol
symbol  : class Controller
location: class test
        Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
// and some more...

I know I should place the jinput.jar in the classpath. Can anyone tell me: “How I can compile the class with the jar in the same directory?”

at the moment I compile and run the code with

# javac *.class
# java test

Does this work:


javac -cp .:JARFILE.jar *.java
java -cp .:JARFILE.jar test

That sets the class path to working directory . and the jar JARFILE.jar. :slight_smile:

no :frowning:

javac -cp .:jinput.jar *.java

same errors

[quote]test.java:5: cannot find symbol
symbol : class Controller
location: class test
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
^
test.java:5: cannot find symbol
symbol : variable ControllerEnvironment
location: class test
Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();
^
test.java:14: cannot find symbol
symbol : class Component
location: class test
Component[] components = ca[i].getComponents();
^
3 errors
[/quote]
I downloaded the latest JInput Binaries and put them in the directory

[quote]jinput-dx8_64.dll jinput-dx8.dll jinput.jar jinput-raw_64.dll jinput-raw.dll jinput-test.jar jinput-wintab.dll libjinput-linux64.so libjinput-linux.so libjinput-osx.jnilib test.java
[/quote]
test.java is my class

Have you got all the required import statements in your .java file? If the classpath wasn’t setup correctly (as it may have been when you first compiled) but the imports were, then the errors should have been with the imports and not the variable declaration.

hmm, no

got no imports at the moment :smiley:

which imports I should have?

Try this:

import net.java.games.input.*;

Some might frown at having a blanket import statement like that, but it will get things moving in the right direction.

I thought java has a autoload functionality like with other classes :smiley:
Know I understand the hole thing, thank you.

unfortunately I got this Errors while executing

[quote]Loading: net.java.games.input.LinuxEnvironmentPlugin
Failed to load library: no jinput-linux64 in java.library.path
java.lang.UnsatisfiedLinkError: no jinput-linux64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1698)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at net.java.games.input.LinuxEnvironmentPlugin$1.run(LinuxEnvironmentPlugin.java:66)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.LinuxEnvironmentPlugin.loadLibrary(LinuxEnvironmentPlugin.java:58)
at net.java.games.input.LinuxEnvironmentPlugin.(LinuxEnvironmentPlugin.java:101)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:156)
at test.main(test.java:6)
net.java.games.input.LinuxEnvironmentPlugin is not supported
[/quote]
Is there a Linux 64Bit Plugin or a workaround for this error?

Tried the Nightly build, same error

It does for classes in java.lang, but not other packages.

Anyway, it looks like you have the classpath now set correctly, but you may need to download an additional lib. Have you checked the documentation? It may mention that there is a file already downloaded that needs to be put in a specific location (not the classpath). The link to endolf’s post you made earlier on has a few points you may have missed.

EDIT: try adding the library path to your java command, eg:

java -Djava.library.path=. classname

thanks

It’s working now

java -Djava.library.path=. -cp .:jinput.jar test

Last question the “libjinput-linux64.so” file have to be in the library path, thats right?

Correct. In your case the library path and classpath happen to include the same folder. You probably want to keep things separate in future otherwise it will start to get messy, but at least now you can focus on writing some code.