PERL   64

jnifix

Guest on 19th May 2022 01:57:53 AM

  1. #!/usr/bin/perl -w
  2. #
  3. # Starts a java runtime, ensuring that the debian JNI module directory is on
  4. # the JNI search path.
  5. #
  6. # Variable $javaRuntime should be modified to suit the particular java
  7. # runtime being used.
  8. #
  9. # Usage: As for the particular java runtime being used.
  10. #
  11. # Copyright (C)  by Ben Burton
  12.  
  13. use strict;
  14.  
  15. # The real java runtime:
  16. my $javaRuntime = '/usr/bin/myjavaruntime';
  17.  
  18. # The debian JNI module directory:
  19. my $debianJNIDir = '/usr/lib/jni';
  20.  
  21. # The command-line options to pass to the real java runtime:
  22. my @commandLine;
  23.  
  24. # The full JNI search path to use:
  25. my $JNIPath = '';
  26.  
  27. # Build the command-line from the arguments given.
  28. foreach my $arg (@ARGV) {
  29.   if ($arg =~ /^-Djava.library.path=(.+)$/) {
  30.     # A component of the JNI search path has been given.
  31.     if ($JNIPath) {
  32.       $JNIPath = $JNIPath . ':' . $1;
  33.     } else {
  34.       $JNIPath = $1;
  35.     }
  36.   } else {
  37.     # Some other argument has been given.
  38.     push @commandLine, $arg;
  39.   }
  40. }
  41.  
  42. # Add the debian JNI module directory to the JNI search path if it's not
  43. # already there.
  44. if ($JNIPath !~ /(^|:)$debianJNIDir($|:)/) {
  45.   if ($JNIPath) {
  46.     $JNIPath = $JNIPath . ':' . $debianJNIDir;
  47.   } else {
  48.     $JNIPath = $debianJNIDir;
  49.   }
  50. }
  51.  
  52. # Call the real Java runtime.
  53. my @fullCommandLine = ( $javaRuntime, "-Djava.library.path=$JNIPath" );
  54. push @fullCommandLine, @commandLine;
  55. exec @fullCommandLine or exit(1);

Raw Paste


Login or Register to edit or fork this paste. It's free.