Author: echatellier Date: 2017-01-04 10:27:29 +0100 (Wed, 04 Jan 2017) New Revision: 4387 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4387 Log: fixes #8787: Impossible d'utiliser R via le package rJava en x64 Modified: trunk/pom.xml trunk/src/main/java/fr/ifremer/isisfish/util/RUtil.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2017-01-03 13:28:55 UTC (rev 4386) +++ trunk/pom.xml 2017-01-04 09:27:29 UTC (rev 4387) @@ -185,7 +185,7 @@ <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-j2r</artifactId> - <version>1.1</version> + <version>1.2-SNAPSHOT</version> <scope>compile</scope> </dependency> Modified: trunk/src/main/java/fr/ifremer/isisfish/util/RUtil.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/util/RUtil.java 2017-01-03 13:28:55 UTC (rev 4386) +++ trunk/src/main/java/fr/ifremer/isisfish/util/RUtil.java 2017-01-04 09:27:29 UTC (rev 4387) @@ -33,6 +33,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -92,15 +93,17 @@ // 1 lignes = commande OK, mais rJava n'est pas installé // 2 lignes = commande OK et rJava est installé if (output.size() == 1) { - //installRJava(); + if (log.isWarnEnabled()) { + log.warn("Can't locate rJava package using Rscript (probably not installed)"); + } } else if (output.size() == 2) { // get install location without "" - String location = output.get(1).trim(); - location = StringUtils.removeStart(location, "\""); - location = StringUtils.removeEnd(location, "\""); + String repository = output.get(1).trim(); + repository = StringUtils.removeStart(repository, "\""); + repository = StringUtils.removeEnd(repository, "\""); // build full library path - location = location.replace('/', File.separatorChar); - location += File.separator + "rJava" + File.separator + "jri"; + repository = repository.replace('/', File.separatorChar); + String location = getArchLibraryPath(repository); setJavaLibraryPath(location); } else if (log.isErrorEnabled()) { log.error("Can't analyze Rscript output. was: "); @@ -111,6 +114,31 @@ } /** + * On some platform, rJava dll are installed into a sub directory depending on system arch. + * + * @param libraryRepository library base repository + * @return rJava lib path depending on arch + */ + protected static String getArchLibraryPath(String libraryRepository) { + String archLibraryPath = libraryRepository + File.separator + "rJava" + File.separator + "jri"; + + String arch = SystemUtils.OS_ARCH; + if ("x86_64".equals(arch) || "amd64".equals(arch)) { + String x64LibraryPath = archLibraryPath + File.separator + "x64"; + if (new File(x64LibraryPath).isDirectory()) { + archLibraryPath = x64LibraryPath; + } + } else { + String i386LibraryPath = archLibraryPath + File.separator + "i386"; + if (new File(i386LibraryPath).isDirectory()) { + archLibraryPath = i386LibraryPath; + } + } + + return archLibraryPath; + } + + /** * Set runtime java library path. * * http://fahdshariff.blogspot.fr/2011/08/changing-java-library-path-at-runtime...