Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correctly install Java for Matlab

Tags:

java

javac

matlab

I am trying to extract a jar file from Matlab code using javac from Library Compiler (java package).

I have set JAVA_HOME to:

C:\Program Files\Java\jdk1.7.0_71

and added to PATH:

C:\Program Files\Java\jdk1.7.0_71\bin.

When I enter java -version in my console, I get java version jdk1.7.0_71 and running javac -version shows jdk1.7.0_71.

However, it seems that matlab could not find javac, thus, I am not able to compile my .m code into a .jar file. When I tried to compile .m code I got the following:

Error: An error occurred while shelling out to javac (error code = -1).
Unable to build executable.
Executing command: ""C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac" -verbose - classpath "...\MATLAB\R2014a\toolbox\javabuilder\jar\javabuilder.jar" -d   "...\features_extraction\for_testing\classes"  "...\features_extraction\for_testing\features_extraction\Class1.java" "...\features_extraction\for_testing\features_extraction\Features_extractionMCRFactory.java" "...\for_testing\features_extraction\Class1Remote.java" "...\for_testing\features_extraction\package-info.java""

This is the directory of my java bin folder and javac.exe exists : ...\Java\jdk1.7.0_71\bin\bin\javac? I found this link for compatibility between Java and Matlab2014a(which is my version) here. What should I check in order to correctly link Matlab to Java? A few days ago Matlab was working correctly with Java.

In my PATH I noticed the existence of the following path: C:\ProgramData\Oracle\Java\javapath in which there are three wrong shortcuts to java.exe, javac.exe, and javax.exe. When I type in matlab console getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode. When I write javac in matlab console I am getting: Undefined function or variable 'javac'.

When I try to built C++ library I got a similar issue: Error: An error occurred while shelling out to mbuild (error code = -1). Unable to build executable.

EDIT: Does the absence of the proper MCR counts in my case?

like image 946
Jose Ramon Avatar asked Jan 08 '15 13:01

Jose Ramon


People also ask

How do I install Java on MATLAB?

If you are not compiling MATLAB code or developing Java applications, you can install the Java Runtime Environment (JRE™) instead of the JDK to run Java applications. Download and install the JDK with the same major version from https://adoptopenjdk.net/. For example, if version -java returns Java 1.8.

Is Java required for MATLAB?

You must have MATLAB Compiler SDK installed. Your Java environment must be properly configured. For details, see Configure Your Environment for Generating Java Packages. Your end users must have MATLAB or MATLAB Runtime installed to run compiled MATLAB code.

Which Java version does MATLAB use?

Accepted AnswerJava 1.3 or greater required.


1 Answers

You said

getenv JAVA_HOME I am getting C:\Program Files\Java\jdk1.7.0_11 while when I wrote version -java I got: Java 1.7.0_11-b21

try to use setenv in MATLAB, doc here http://www.mathworks.com/help/matlab/ref/setenv.html

setenv('JAVA_HOME','C:\Program Files\Java\jdk1.7.0_71');
setenv('PATH','C:\Program Files\Java\jdk1.7.0_71\bin');
like image 170
brettmichaelgreen Avatar answered Oct 07 '22 00:10

brettmichaelgreen