In fact the JVM was complaining that the library path was relative, not absolute. The error is in the findLibrary method of PluginLoader : instead of
String libpath = parentDir.getPath() + File.separator + System.mapLibraryName(libname);
it should be something like :
String libpath = parentDir.getAbsolutePath() + File.separator + System.mapLibraryName(libname);
Well there are several other changes involved to support correctly absolute paths, I’ll post the code here so that it can be tested before submitting an official RFE + patch ;D
All these changes are made in net.java.games.input.DefaultControllerEnvironment.
- replace method scanControllers() with
private void scanControllers() {
String pluginPathName = System.getProperty("jinput.controllerPluginPath");
if(pluginPathName == null) {
pluginPathName = "controller";
}
File[] dirs = getPotentialDirectories(pluginPathName);
for(int i = 0; i < dirs.length; i++) {
scanControllersAt(dirs[i]);
}
}
- replace method scanControllersAt(String path) with
private void scanControllersAt(File file) {
try {
Plugins plugins = new Plugins(file);
Class[] envClasses = plugins.getExtends(ControllerEnvironment.class);
for(int i=0;i<envClasses.length;i++){
try {
if (DEBUG) {
System.out.println("ControllerEnvironment "+
envClasses[i].getName()
+" loaded by "+envClasses[i].getClassLoader());
}
ControllerEnvironment ce = (ControllerEnvironment)
envClasses[i].newInstance();
addControllers(ce.getControllers());
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
(this is exactly the same method, except that it handles directly Files)
- add the following methods
private String[] getPotentialPaths(String pluginPathName) {
String javaHomePath = System.getProperty("java.home") + File.separator + "lib" + File.separator + pluginPathName;
String userDirPath = System.getProperty("user.dir") + File.separator + pluginPathName;
String rawPath = pluginPathName;
String[] allPaths = { javaHomePath, userDirPath, rawPath };
return allPaths;
}
private File[] getPotentialDirectories(String pluginPathName) {
String[] paths = getPotentialPaths(pluginPathName);
File[] dirs = null;
if(paths.length > 0) {
File[] allDirs = new File[paths.length];
int validDirCount = 0;
for(int i = 0; i < paths.length; i++) {
try {
File f = (new File(paths[i])).getCanonicalFile();
if(f.exists()) {
boolean duplicated = false;
for(int j = 0; j < validDirCount; j++) {
duplicated |= f.equals(allDirs[j]);
}
if(! duplicated) {
allDirs[validDirCount] = f;
validDirCount ++;
}
}
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
dirs = new File[validDirCount];
System.arraycopy(allDirs, 0, dirs, 0, validDirCount);
}
else {
dirs = new File[0];
}
return dirs;
}
getPotentialPaths constructs the paths to be explored.
getPotentialDirectories makes sure that no directory will be searched twice by comparing files (trying to load the same library several times generates errors).
[EDIT] Sorry, my code indentation got screwed up by this damn forum >:( If you are interested, I can mail you the file.