• Post Reply Bookmark Topic Watch Topic
  • New Topic

specifying a JVM arg programmatically..  RSS feed

 
Scott Presley
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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...
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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 ]
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!