Matlab and Java integration
Asked Answered
A

1

4

I have done image processing in MATLAB and build my GUI in Java. I want to integrate MATLAB into Java. I want to use MATLAB Builder for this purpose. I want also to use neural network for classification. There are some excel files also. Is it possible that this code will be integrated in Java?

My other question is that I want used MATLAB BuilderJA to know how it works. When I type java -version command, it gave me this error.

??? Attempt to execute SCRIPT java as a function:
C:\Program Files\MATLAB\R2009b\toolbox\matlab\general\java.m
 C:\Program Files\Java\jdk1.6.0_21

When I use build command it gave me this error.

'javac' is not recognized as an internal or external command,
operable program or batch file.
Error: An error occurred while shelling out to javac (error code = 1).
Unable to build executable.

I have JDK installed. The path is C:\Program Files\Java\jdk1.6.0_21. I am using R2009b version

I want to run my code in Java, but I do not know how to fix this error. Can any one tell me how to resolve this error?

Angular answered 27/7, 2011 at 10:7 Comment(7)
Can you check if C:\Program Files\Java\jdk1.6.0_21\bin is on the PATH? Also you can create a JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21 environment variable..Asis
How can I check thatC:\Program Files\Java\jdk1.6.0_21\bin and how can I create environment variable?Angular
some instructions: How do I set or change the PATH system variable?Asis
Note that not all of the functionality of Neural Networks Toolbox is supported by MATLAB Compiler or MATLAB Builder for Java - in particular, you can only deploy pretrained networks, not the network training commands. See: Compiler Support for ToolboxesGeyserite
@Asis I have created JAVA_HOME environment variable. But when I entered the command !java-version it again gave me error java is not recognized as external or internal command, operable program or batch file now what should I do?Angular
@Sarah: as previously mentioned, you must have the bin directory of both the JDK and JRE in the PATH environment variable: PATH=%SystemRoot%\system32;....;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program Files\Java\jre6\bin. By putting stuff on the path, you tells your system where to find the executables java.exe and javac.exe you want to useAsis
@Amro: i have put bin of both jdk and jre and exe of javac but still it is giving the same error: javac is not recognize as internal and external command. why it is not recognizing??Angular
D
0

The first error message which you get when you type java -version is a bit misleading; instead of

java -version

you need to say

!java -version

since you want to call an external program and not a MATLAB script or function. As stated in the comments by Amro this will only work if the directory containing java.exe is on your path. See Running External Programs in the MATLAB help for more info.

The error message you get comes from the fact that

  • there happens to be a file java.m and MATLAB thinks you are trying to call this file
  • that file only contains comments, since java is actually a sort of keyword in MATLAB, see doc java.
  • MATLAB realizes that you are not using the keyword in its correct form (which would be to call java.something to create an object of class something) since you give a parameter
  • MATLAB ends up telling you in a strange way that java doesn't accept parameters (even though java.m does not contain the script, only its documentation)

Note that if you don't want to add the directory containing java.exe and javac.exe to the path, you could also try calling them with their full path name:

!C:\Program Files\Java\jdk1.6.0_21\blablabla\bin\javac.exe
Denticulation answered 27/7, 2011 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.