I have inherited a large number of Java files with classes I am trying to call from Mathematica via J/Link. They are legacy and am not at liberty to modify. A few are used on command-line scripts (with static methods, no constructors [hence no JavaNew]). Unfortunately they require the user to launch the JVM at a specific directory.

Loading Java in Mathematica via J/Link with -Duser.dir=theSpecificDirectoryName -DsomeEnvironmentVariable=someValue neither changes the current working directory nor System.getenv(someEnvironmentVariable) return "someValue."

Question: How to make the JVM (or J/Link?) use these values ("theSpecificDirectoryName" as its current working directory and "someEnvironmentVariable") in Mathematica?


  • $\begingroup$ Does running setProperty["user.dir", "theSpecificDirectoryName"] after loading JLink have no effect? For environment variables I find if I launch Mathematica from the command line it will inherit whatever variables I had set. $\endgroup$
    – Jason B.
    Apr 9 '20 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.