Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 76486
366
  • 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: 24204
44
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 ]
     
    You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic