2

I have an application which requires the use of 6 different SWT libraries (for each OS of MacOSX 32 and 64 bit, Windows 32 and 64 bit, and Linux 32 and 64 bit).

The application on which I am working I want to be cross-platform and fairly user proof (as in, it should require as little input from the user as possible to get the program to launch).

Is there a way to, based on what case with which I am dealing, tell the application "Hey, use THIS library"?

Something like

if (Platform.isMac()){
    if (Platform.is64Bit()) //Use Mac 64 bit Library
    else //Use Mac 32 Bit Library
//Same for Windows
//Same for Linux

Is that possible?

EDIT

I know how to determine the OS. I just need to know how to load a specific jar at run time as a dependent library of another library (say I have a library that requires SWT, I need to be able to tell THAT library WHICH SWT.jar to load based on the OS in which I am currently operating).

Will
  • 3,413
  • 7
  • 50
  • 107
  • Possible duplicate http://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java – Alkis Kalogeris Sep 27 '14 at 22:12
  • No. I know how to determine the OS. What I need to know is how to specify which JAR to load. – Will Sep 27 '14 at 22:13
  • Oh my bad, now I understand what you want. – Alkis Kalogeris Sep 27 '14 at 22:18
  • So basically what you want is how to load jars/packages at runtime. Maybe this can help? http://stackoverflow.com/questions/194698/how-to-load-a-jar-file-at-runtime – Alkis Kalogeris Sep 27 '14 at 22:22
  • I think you could try creating separate child `Classloader`for your platform specific libs depending on your Platform filter condition. – sambi reddy Sep 28 '14 at 19:31
  • @sambireddy I like that idea it sounds like what I need. The next question I'd have to ask is do you have a link to a concise example of how I would go about doing that (not the "determine my architecture part" but the "create separate classloaders" part. If you can give me that in the form of an answer (and I can hammer out the details and make it work) I will accept it. – Will Sep 28 '14 at 22:43
  • @alkis That looks like for what I am looking... – Will Sep 28 '14 at 22:51

1 Answers1

0

If your java program uses platform specific dependencies you should provide different start scripts for it. Just keep it simple. Your scripts can determine the used jdk architecture and configure the proper classpath for it. I never encountered a java program trying to bootstrap the architectual environment. That's because of the massive efford it would take, except for architectural jni calls which is however not the case with swt.

Hannes
  • 2,018
  • 25
  • 32
  • Any chance you could provide an example, or a link to what you are talking about? – Will Sep 28 '14 at 22:42
  • Startup scripts for Apache Tomcat for example. You could also try the maven appassembler plugin. – Hannes Sep 29 '14 at 07:32