Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java requirements, JAVA_HOME, JRE path setting unclear #32

Closed
tmwaring opened this issue Nov 16, 2019 · 7 comments
Closed

Java requirements, JAVA_HOME, JRE path setting unclear #32

tmwaring opened this issue Nov 16, 2019 · 7 comments

Comments

@tmwaring
Copy link

tmwaring commented Nov 16, 2019

Dear @nldoc,

Excited to use nlrx. It looks like the best way to connect R and NetLogo yet. I am having trouble getting it to work, and the problem seems to be the java version, or failing to connect to the JRE (java runtime environment). I have:

  • MacOS 10.14.6
  • R 3.6.1
  • NetLogo 6.1.0
  • Java 1.8.0_221 (Installed in "Library/Internet Plug-Ins")
  • Java 1.6.0 (I think this is "Apple Java", in Library/Java/JavaVirtualMachines)

I use the code:

netlogopath <- file.path("/Applications/NetLogo 6.1.0")
modelpath <- file.path(netlogopath, "/Applications/NetLogo 6.1.0/models/Sample Models/Biology/Wolf Sheep Predation.nlogo")

nl <- nl(nlversion = "6.1.0", nlpath = netlogopath, modelpath = modelpath, jvmmem = 1024)

nl@experiment <- experiment(expname="wolf-sheep", outpath="~/Desktop/", repetition=1, tickmetrics="true", idsetup="setup", idgo="go", idfinal=NA_character_, idrunnum=NA_character_, runtime=50, evalticks=seq(40,50), metrics=c("count sheep", "count wolves", "count patches with [pcolor = green]"), variables = list(), constants = list("initial-number-sheep" = 20, "initial-number-wolves" = 20, "model-version" = "\"sheep-wolves-grass\"", "grass-regrowth-time" = 30, "sheep-gain-from-food" = 4, "wolf-gain-from-food" = 20, "sheep-reproduce" = 4, "wolf-reproduce" = 5, "show-energy?" = "false"))

nl@simdesign <- simdesign_simple(nl=nl, nseeds=3)

results <- run_nl_all(nl)

And I get this error:

JAVA_HOME undefined, using java from path. For control over exact java version, set JAVA_HOME Exception in thread "main" java.lang.UnsupportedClassVersionError: org/nlogo/headless/Main : Unsupported major.minor version 52.0

How do I set JAVA_HOME, as it is not a package variable, apparently? Thanks!

@tmwaring tmwaring changed the title Java requirements, java path setting unclear Java requirements, JAVA_HOME, JRE path setting unclear Nov 16, 2019
@tmwaring
Copy link
Author

tmwaring commented Nov 16, 2019

After searching stackoverflow, I learned how to set JAVA_HOME in the terminal. I also installed a Java 1.8.x JDK. And how NLRX is running. Despite this, I still get the error:

JAVA_HOME undefined, using java from path. For control over exact java version, set JAVA_HOME

for every simulation NLRX runs. I suspect this is not ideal. How to set JAVA_HOME in a way that NLRX likes, so that it is persistent? Even more importantly, it would be good to set JAVA_HOME from within NLRX, or do something that has the same effect, telling LNRX where the right JRE is.

Here is how I set JAVA_HOME on MacOS, from the terminal:
echo $JAVA_HOME
to make sure it's set to a good version of the JRE. Running the line:
/usr/libexec/java_home
gives me the output:
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
then set JAVA_HOME with this line:
export JAVA_HOME=$(/usr/libexec/java_home)

Also, to discover your java version, from the terminal:
java -version

@nldoc
Copy link
Contributor

nldoc commented Nov 19, 2019

@tmwaring thank you very much for your feedback.
Good to hear, that you could solve part of the problem by installing the Java 1.8.x JDK.
It took a while to figure out the problem because I did not have a mac at hand. Luckily, a colleague helped me out with debugging this issue. We could reproduce the problem (run_nl_all was running succesfully but the warning message still appeared). We set JAVA_HOME from the terminal, as you did. Interestingly we were able to run nlrx succesfully from an R session started in the terminal without the warning.

We figured out it might be a problem with Rstudio not sourcing the environmental variables correctly. Luckily, we found a way to solve this problem. You just need to set the JAVA_HOME environmental variable from within your Rstudio session, like this:
Sys.setenv(JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home")
You may add this line to your .Rprofile file to execute this code on startup of R.
You can verify this by executing system("echo $JAVA_HOME"). Before executing the Sys.setenv() line above it will probably report "", whereas after running the Sys.setenv() line above, it should report the path to your java installation.

@tmwaring
Copy link
Author

Dear @nldoc,

Wow, good sleuthing! Because nlrx was working (on three different machines), I was just accepting the error. But your discovery that RStudio is not sourcing the environmental variables correctly explains everything. I've tested your new R code, and can confirm it works just as you said!

Thanks so much!

@nldoc
Copy link
Contributor

nldoc commented Nov 19, 2019

My pleasure. I am glad the solution works out on your system as well :)

@nldoc nldoc closed this as completed Nov 19, 2019
@tmwaring
Copy link
Author

tmwaring commented Nov 19, 2019 via email

@nldoc
Copy link
Contributor

nldoc commented Nov 19, 2019

Thanks again for your very helpful feedback.
You are right, currently there is not much console output. But in my opinion it is also challenging to find the right mix of useful console output vs spamming the console. But I will defenitely think about your suggestions. I like the idea of having a summary output, maybe by providing an nl-object specific output for the basic summary() function. Then, one could do summary(nl) to get a nice formatted overview of the current nl object. I will check that out soon. I am not sure about interactive console queries, personally I do not find them really helpful. For doing test runs, you can also use the run_nl_one() function.
And documentation-wise, I hope you did check out our webpage?
The link is somewhat hidden at the top of the github repository, so I just wanted to make sure you are aware of that webpage, which contains a lot more detailed instructions and examples (check out the "More" menu at the top).
Best regards

@tmwaring
Copy link
Author

tmwaring commented Nov 19, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants