2

I have some external C code which has been built for multiple platforms(Windows, Linux, Mac), and want to package them all in a single .jar so that this .jar can be used as a library regardless of the platform.

This would allow me to pass a Java project around from computer to computer with the same single external library.

There are existing class files which are calling the code using JNI, and those classes are the ones which differ on different platforms. In the current state, we swap out jars with different classes which call native functions for that particular platform.

Is there a way to package them in such a way that I can dynamically load the correct class file without having to use Ant/Maven or create an abstraction layer?

Lincoded
  • 425
  • 2
  • 13

1 Answers1

-1

You can't pack native files in a jar. The class files however can be like regular class files.

You can pack everything into a zip file if you want? as an alternative.

To load the correct file: Class.forName() should suffice. Although make sure the files fall into your class path, or dynamically modify your class path to search from URLs.

Community
  • 1
  • 1
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
  • 1
    You can pack native files into a jar(which is what is currently done, with one jar for each platform). However, I didn't want to create an abstraction layer(which would be necessary if using Class.forName()). – Lincoded Oct 19 '12 at 18:55
  • @Lincoded you don't want to create an abstraction layer? which means you want to call functions from the libraries without having a stub Java class? – Aniket Inge Oct 19 '12 at 18:57
  • 1
    We have existing classes which call the functions in the native implementation, and currently swap out the class files in the jars for different platforms. We would like to instead package all of the files into one jar. – Lincoded Oct 19 '12 at 19:00