Saturday, April 29, 2017

Solution to erroneous "please update your maxent program to version 3.3.3b or later" error when running maxent from dismo & ENMTools

I originally encountered this problem when trying to run maxent from ENMTools; but it turns out it was a combination of problem with the dismo package, and with my Mac machine having different versions of java installed (1.6 and 1.8).

I am pasting the solution that worked for me below, and to other relevant lists if I find them, since I didn't find a direct answer online.

Thanks - Nick


Solution to erroneous "please update your maxent program to version 3.3.3b or later" error when running maxent from dismo


Hi all,

I spent about 2 hours figuring this out on my Mac, so I might as well share it, as I didn't find anything else on specifically this problem online. 


SUMMARY: After installing rJava, dismo, and downloading/pasting the new maxent.jar file into the dismo install, I still got this error: "please update your maxent program to version 3.3.3b or later" 

RESOLUTION: The error was erroenous, it was actually due to a java mismatch error, in R/R.app on Mac OS X

I am posting my notes on this for google-ability, perhaps it will help others, or perhaps it will help myself when I forget all of this and get stuck with the same error on a mac laptop or something in 6 months!



I. SETUP

MacOSX El Capitan, Version 10.11.6
Use R from Terminal, and from R.app



II. PROBLEM:

I got set up to run maxent from R/dismo. Steps:

- installed rJava 
- installed dismo
- Downloaded the new maxent.jar (3.4.0, released December 2016 I think) from:
http://biodiversityinformatics.amnh.org/open_source/maxent/
- copied the jar file into the java directory of the dismo install:
/Library/Frameworks/R.framework/Versions/3.3/Resources/library/dismo/java/


But, when, when running the example code in ?maxent, I got:

Loading required namespace: rJava
Error in .getMeVersion() : 
  please update your maxent program to version 3.3.3b or later. This version is no longer supported. 
You can download it here: http://www.cs.princeton.edu/~schapire/maxent/'

Seeing as I had the newest version of maxent, this was confusing.




III. DIAGNOSIS

It turns out that this was the real problem.  Inside the maxent.R code is the following:

https://github.com/cran/dismo/blob/master/R/maxent.R
=============================
.getMeVersion <- function() {
jar <- paste(system.file(package="dismo"), "/java/maxent.jar", sep='')
if (!file.exists(jar)) {
stop('file missing:\n', jar, '.\nPlease download it here: http://www.cs.princeton.edu/~schapire/maxent/')
}
.rJava()
mxe <- rJava::.jnew("meversion") 
v <- try(rJava::.jcall(mxe, "S", "meversion") )
if (class(v) == 'try-error') {
stop('"dismo" needs a more recent version of Maxent (3.3.3b or later) \nPlease download it here: http://www.cs.princeton.edu/~schapire/maxent/
\n and put it in this folder:\n',
system.file("java", package="dismo"))
} else if (v == '3.3.3a') { 
stop("please update your maxent program to version 3.3.3b or later. This version is no longer supported. \nYou can download it here: http://www.cs.princeton.edu/~schapire/maxent/'")
}
return(v)
}
=============================


This bit of the code determines the version of maxent.jar being used:

mxe <- rJava::.jnew("meversion") 
v <- try(rJava::.jcall(mxe, "S", "meversion") )

...however, "rJava::.jcall" was giving an error due to a mismatch in java versions.  Mac OS X comes with Java 1.6 installed, but I had installed the newest java for various other applications (Beast2 etc.)

The messages were slightly different in Terminal R and R.app, but they were messages like this:

java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52.0
java.lang.UnsupportedClassVersionError: density/Utils

These produce a "try-error" in "v", leading to this code mistakenly assuming that the problem is an old maxent.jar:

===============
mxe <- rJava::.jnew("meversion") 
v <- try(rJava::.jcall(mxe, "S", "meversion") )
if (class(v) == 'try-error') {
stop('"dismo" needs a more recent version of Maxent (3.3.3b or later) \nPlease download it here: http://www.cs.princeton.edu/~schapire/maxent/
\n and put it in this folder:\n',
system.file("java", package="dismo"))
===============





I was able to find my java installs, on my Mac, with:

cd /Library/Java/JavaVirtualMachines/
ls

I had:

1.6.0.jdk
jdk1.8.0_51.jdk




IV. SOLUTION(S)

Various hints were on this page:
http://stackoverflow.com/questions/26948777/how-can-i-make-rjava-use-the-newer-version-of-java-on-osx

...but I did *not* find that I had to use sudo to re-install anything.  For me, what worked was:





SOLUTION: R from Terminal

1. From the Terminal, run: "R CMD javareconf"

2. Enter R, reinstall rJava *from source*, e.g.:

install.packages('rJava',,'http://www.rforge.net/')

3. I also re-installed dismo from source, and then re-pasted maxent.jar into /Library/Frameworks/R.framework/Versions/3.3/Resources/library/dismo/java/

Then, everything worked:

library(rJava)
library(dismo)
maxent()
> This is MaxEnt version 3.4.0 





V. NEW PROBLEM

However, when I opened R.app and tried running maxent(), I now got a new error on library(rJava):

========================================
library(rJava)

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rJava/libs/rJava.so
  Reason: image not found
Error: package or namespace load failed for ‘rJava’
========================================



VI. NEW SOLUTION

The solution to this, in R.app, was:

========================================
dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib')

library(rJava)

maxent()
> This is MaxEnt version 3.4.0 
========================================


To make this "permanent", I added:

dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib')

...to my .Rprofile file, an invisible file (you might have to create it in a plain-text editor) in your mac user directory ("cd ~").


This works, but presumably will have to be changed if/when I update java.




VII. RECOMMENDATION

This bit of code in the dismo R package should probably be updated:

===============
mxe <- rJava::.jnew("meversion") 
v <- try(rJava::.jcall(mxe, "S", "meversion") )
if (class(v) == 'try-error') {
stop('"dismo" needs a more recent version of Maxent (3.3.3b or later) \nPlease download it here: http://www.cs.princeton.edu/~schapire/maxent/
\n and put it in this folder:\n',
system.file("java", package="dismo"))
===============

...to (1) distinguish between Java errors and old Maxent versions; and (2) the link http://www.cs.princeton.edu/~schapire/maxent/ should be updated to the new link, for the open-source maxent, online at the American Museum: http://biodiversityinformatics.amnh.org/open_source/maxent/

I am posting this to a couple of relevant lists, perhaps it will help others, or perhaps it will help myself when I forget all of this and get stuck with the same error on a mac laptop or something in 6 months.

Thanks,
Nick

Nick Matzke contact info
Usually in Australia:
================================
Nicholas J. Matzke

Professional introduction: http://www.nickmatzke.net
Active work website: http://phylo.wikidot.com/nicholas-j-matzke

Discovery Early Career Researcher Award (DECRA) Fellow
DECRA granted by ARC (Australian Research Council)
Division of Ecology and Evolution (E&E)
College of Medicine, Biology & Environment (CMBE)
Research School of Biology (RSB)
The Australian National University

Room 208, Building 116, Gould Wing
The Australian National University
ACT 2601 AUSTRALIA

Email: nickmatzke.ncse@gmail.com
nick.matzke@anu.edu.au
Skype: nicholas.matzke
Cell (preferred): +61 0410-726-191
Office (not preferred): +61 02 612 52 450
================================

Sometimes at meetings in the U.S.:
================================
Emails: same
Phone: 510-301-0179
================================

7 comments:

  1. Useful information that i have found. don't stop sharing and Please keep updating us..... Thanks

    ReplyDelete
  2. More useful info: https://mail.google.com/mail/u/0/#inbox/15c36a3fc435eb99

    ReplyDelete
  3. Hi, this one does not work on my Mac 10.10.
    library(rJava) has no issue, it loads without error,
    but maxent gives the same message, version 3.3.3b or latter
    the Maxent works stand alone, but not in dismo.

    any solution please.
    thanks

    ReplyDelete
  4. Thanks Nick. When I tried this
    library(rJava)
    library(dismo)
    maxent()

    I have this error:

    Error in .jcheck(silent = TRUE) :
    No running JVM detected. Maybe .jinit() would help.

    And this results in
    dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib')
    Error in dyn.load("/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib") :
    unable to load shared object '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib':
    dlopen(/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/server/libjvm.dylib, 6): image not found

    Any ideas? Thx.

    ReplyDelete
    Replies
    1. Have you checked to see if you could find that file at that location? It looks like it's just looking for some file that's part of your java installation and not finding it.

      Delete
  5. Hey, thanks for the post!

    I've tried your fixes, and several others, and I'm right back to where I started--

    entering:
    library(rJava)
    library(dismo)
    maxent()

    Yields:
    "please update your maxent program to version 3.3.3b or later". I'm running R 3.4.1 and RStudio 1.0.143 on Mac OS 10.12. I get the error regardless of whether I use R or RStudio (or how RStudio was launched). Any more ideas on how to solve this?

    ReplyDelete