Java Project with native libraries for different platforms

I have a java project that uses JOGL and therefore needs to include different native libraries for different platforms. Now I want to set up the eclipse project to automatically chose the correct libraries. In the .classpath file you can specify one native location:

<classpathentry kind="lib" path="lib/jogl/jar/jogl.all.jar"> <attributes> <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="de.yogularm.desktop/lib/jogl/windows-amd64"/> </attributes> </classpathentry>

If multiply classpathentries specify a native location, Eclipse also tries to load the libraries for other platforms and fails.

How can I make eclipse chose the directory? I want to share the project and make setup for further developers as easy as possible.

-------------Problems Reply------------

You can create several .classpath files (.classpath_Windows, .classpath_Linux etc.) and then create symbolic link to required version (Win/Lin/Mac) named ".classpath"
The problem will appear whan you want to change any entry inside any .classpath_XXXXXXX - then you will have to update other .classpath files.

Eclipse lacks the feature you want. So, you can do it from Java.

Instead of calling System.loadLibrary, call System.load. This requires you to write code to calculate the correct pathname based on the current platform. You'll need to use -D to pass a value in to say what the current platform is, or read it from a file.

This removes java.library.path from the equation.

If your JNI library has dependencies, you will also need to set PATH, LD_LIBRARY_PATH, or DYLD_LIBRARY_PATH. Unless you take the further step of looking at For Windows, however, the necessary machinations with the delay-loader aren't in there.

I may be wrong, but I think the native libraries are things like DLLs, shared objects, etc., and don't go on the classpath at all. Each environment will have something like a PATH variable or the like, which will need to include the native libraries. The user may have to some configuration (either within Eclipse, or via environment variables).

Libraries are not searched within the classpath, the system PATH and the property java.library.path.

In your case may be a custom ClassLoader implementation, especially the findLibrary(..) and loadLibrary(..) methods. This would allow to select an appropriate library based on the detected OS.

Category:java Views:0 Time:2012-01-27
Tags: java eclipse

Related post

Copyright (C), All Rights Reserved.

processed in 0.156 (s). 11 q(s)