• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

specifying a JVM arg programmatically..

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please don't ask how i got myself into this predicament...

i run the following command to start my applicaiton



there is a dll contained in the lib folder that one of my third-party classes relies on to write to the windows registry.

I'm stuck though... is part of a new feature i'm rolling out to my customers, but they have an existing exe wrapper that calls my java application and it does not include the this new jvm arg...

is there anyway to programmaticlly specify the java.library.path VM argument in the code? I tried


but it fails...
 
Marshal
Posts: 79699
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do a search for "when Runtime.exec() won't" on Google and you get the classic paper by Michael Daconta. He describes an example starting the JVM; you can probably adapt that to serve your present purposes.
Also check the ProcessBuilder class which makes the collection of information from the Streams easier.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Scott,

The short answer is sadly "no". By the time the JVM is running, it's too late to set java.library.path. You can change the system property, but the JVM won't ever pick up a new value. The only way to supply this parameter is as a startup option
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are some workarounds, if your question is instead "how do I load the DLL?"

Presumably you're using System.loadLibrary("library") or Runtime.getRuntime().loadLibrary("library") to try to load the native code, and library.dll isn't found. You can instead do one of the following:
  • Pass the full path to System.load("\\path\\to\\library.dll") or Runtime.getRuntime().load("\\path\\to\\library.dll").
  • From your startup code, create a subclass of URLClassLoader to load the rest of your code, and override findLibrary() to return "\\path\\to\\library.dll" when passed "library".

  • Hopefully you won't hard-code the new library path.

    (Edited for better formatting.)
    [ October 30, 2008: Message edited by: Carey Evans ]
     
    If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic