2

I usually use chilkat library (http://www.chilkatsoft.com/java.asp) develop only with windows. but this library have each library file for each platform, and today I have to do it cross platform.

Example

  • Windows x64 use win64.dll
  • Windows x84 use win32.dll
  • Linux x64 use linux64.so
  • Linux x32 use linux32.so
  • Max OSX use osx.jnilib

This my source code for include chilkat library when use windows only.

static {
    try {
        System.loadLibrary("lib/win64");
    } catch (UnsatisfiedLinkError e) {
        try {
            System.loadLibrary("lib/win32");
        } catch (UnsatisfiedLinkError e2) {
            System.err.println("Native code library failed to load.\n" + e2);
            System.exit(1);
        }
    }
}

And now I no idea. How include each library file on java application for cross platform ?

Please guide best way to me.

Thank you.

Edit1: sorry for confusion. i know how find os.name on runtime. but this question i mean how include each library file for run each platform.

Jerry
  • 70,495
  • 13
  • 100
  • 144
Jaynova
  • 514
  • 1
  • 4
  • 11

2 Answers2

1

You can use JarSplice and create multiple jars for many platforms. http://ninjacave.com/jarsplice

nervosol
  • 1,295
  • 3
  • 24
  • 46
1

You can use the os.name System property to determine what OS you are running on...

 String os = System.getProperty("os.name");
 if (os.startsWith("Mac")) {
     // Running on Mac
 } else if (os.startsWith("Windows")) {
     // Running on Windows
 }

Sorry, don't have a Linux box to test on ;)

On Windows, you can try testing the PROCESSOR_ARCHITECTURE environment variable, which when running within a x64 bit process state, should return AMD64

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • sorry for confusion. i know how find os.name on runtime. but this question i mean how include each library file for run each platform. – Jaynova Jun 20 '14 at 07:17
  • 1
    Include all of them, load the one you need based on the OS... – MadProgrammer Jun 20 '14 at 07:19
  • You mean, i can use "System.loadLibrary("lib/osx.jnilib");" on Mac and "System.loadLibrary("lib/linux64.so");" on Linux when know os name running ? – Jaynova Jun 20 '14 at 07:24
  • I would, but that's me. You could setup separate "distributions" which only included the required library(s), but I would make the code used to load them the same – MadProgrammer Jun 20 '14 at 07:26