Question

I am listening some path in a computer by using JNotify api. But since watching the file system is a relatively low level thing it uses different libraries for different operating systems, such as linux, mac or windows. and 32, 64 bit makes difference too. my question is how to select which library to use. when I add all of them to the build path, it causes error. i need some configurations i think but I dont know how:/ any help would be appreciated. btw I use java on eclipse.

Was it helpful?

Solution

You can find out what platform you are running on using the os.arch/os.name system property. See this answer to a similar question for more details.

As for loading the correct library, you could package each of the platform specific classes into their own jar and load them dynamically. See this question for an example of that.

OTHER TIPS

System.getProperty("os.name");

If you use Maven you can have a profile for each target and build each target OS a specific .jar file.

Trying to create a single binary for every platform is a complicated thing. I would create a distribution for each target OS separately to avoid complicating the application.

You can use system-level properties, like os.arch, os.name and os.version, e.g.:

String architecture = System.getProperty("os.arch");
String os = System.getProperty("os.name");

On my machine it returns "amd64" and "Windows 7" respectively. You can also the file.separator system property knowing that on Linux and Mac it should return a forward-slash ("/") and on Windows it should return a back-slash ("\")/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top