matlab deploytool to java package javac error - java

I'm trying to wrap a program of mine to work with java.
I tried a simple "hello world" first,
-hello world.m-
disp('hello world');
I used deploytool and selected java package.
when it reached this line:
Executing command: "javac -verbose -classpath "C:\Program Files\MATLAB\R2009b\toolbox\javabuilder\jar\javabuilder.jar" -d "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\classes" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\helloworld.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\DeployTutorial2MCRFactory.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\helloworldRemote.java" "C:\Users\shachar\Documents\MATLAB\deployTutorial\deployTutorial2\src\deployTutorial2\package-info.java""
I got 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.
btw: when I tried standalone application / c/c++ shared library it has been compiled successfully.
thanks in advance

Possibly the Java SDK is not installed or properly configured on your machine. Open a system terminal and execute the following two commands:
java -version
javac -version
If they both work you should proceed with the examples from the MATLAB help. If not install the Java SDK.

First you should install JAVA.
Then you must set the environment variable in "my computer"
Add a new variable named "JAVA_HOME" and set its value to your jdk path
like D:\Program\Java\jdk1.6.0_25
Then restart your matlab
and type
getenv JAVA_HOME
you should get
ans=
D:\Program\Java\jdk1.6.0_25

Related

Java and javac not working in cmd. Both java and javac "is not recognized as an internal.."

I am having som trouble with java, i have tried to fix my Path, but i am new to programming and don`t know what to do.
I have java installed at : C:\Program Files\Java\jdk1.8.0_92\bin
and at : C:\Program Files (x86)\Java\jdk1.8.0_91\bin
Here are some screenshots from my system variables: This pops up when i click on the system variable "Path", see the other picture.
System variables
When I am in cmd, and writing java -version or javac -version, I get this message:
"java/javac is not recognized as an internal or external command, operable program or batch file".
Have tried to restart cmd every time i have changed the path.
Try Setting separate variables for JDK & JRE
Also give a backslash "\" after bin in the case of both JDK & JRE
Hope this works
First go to this path to make sure that it is right.
second try to restart your cmd and try again.

Correctly install Java for 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?
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');
Following from the answers in this link
http://www.mathworks.com/matlabcentral/answers/131639-matlab-deploytool-not-working-fails-while-building
seems like you have to install JDK 1.7.0_11-b21, which is the one your MATLAB version is compatible with for compiling into jar. Also, after installing that specific version, you should modify the JAVA_HOME and PATH environment variables. Try that to see if it helps.
I was having a very similar problem with my installation.
I set the environment variable (press > type env > Enter) JAVA_HOME (under "User variables") to my JDK home directory (not the bin folder) without any trailing \ or ;.
The problem occurs because MATLAB cannot execute javac properly, however, in order to work out exactly what MATLAB is trying to execute (which is not working) we need to use the command window and not the Library Compiler.
It appears you have already done this but for completeness I will add the process here for others.
To find what MATLAB executes, click "Open log file" and copy the entire first line.
Paste the first line in the MATLAB command window and add -v to the end.
Press enter to run the command and note the "Executing command:" that is printed to the screen.
Once you have the "executing command" that MATLAB returns for you, check the first path in that command and make sure it matches your javac file.
In your original post you have done this and posted
C:\Program Files\Java\Java\jdk1.7.0_11\bin\javac
a path which contains \Java\Java, if this isn't a typo then it may be a problem as it is not the default Java installation path. You also say after that your installation is at
...\Java\jdk1.7.0_71\bin\bin\javac
which contains \bin\bin and is also not the default java bin install directory, perhaps another typo?
If the path to javac matches exactly you could try copying and pasting the "executing command" into your OS's command window (+R > cmd > Enter) and looking for errors. By doing this we can remove ourselves from the MATLAB installation and if errors still exist it likely has nothing to do with MATLAB.
To see if the same problem could be caused by other environment variables I removed every other path to a java installation (keeping JAVA_HOME) in my environment variables. MATLAB uses the absolute path to the java installation and so it was still able to compile with javac using only the JAVA_HOME environment variable.

java command line compilation

I have a simple, single file java program that relies on a single static jar. The java code and the jar reside in the same directory. For this one-off solution I don't want to bring in the weight of ant or maven, and just want to compile it directly.
On my dev box, the following compiles and runs my code fine:
javac -cp ".;dependency.jar" File.java
java -cp ".;dependency.jar" File
However, on my test box, the java command fails, and I get the following output:
Error: Could not find or load main class File
If I change my classpath arg to -cp "." I get the following output:
Exception in thread "main" java.lang.ClassNotFoundException: dependency
My dev box is 64-bit Windows/Cygwin and java version 1.7.0_55. My test box is 64-bit Linux and java version 1.7.0_45.
What is going wrong on my test box?
The classpath separator character is different on Linux (and on Unix) than it is on Windows. It's ; on Windows, but it's : on Linux (and Unix).
Try this on Linux:
javac -cp ".:dependency.jar" File.java
java -cp ".:dependency.jar" File

Ant Path error when performing Apache Cordova Helloworld example for amazon-fireos

I am working through Apache Cordova Amazon-fireos guide
But I am getting an Ant path error when performing "cordova platform add amazon-fireos" command. Looking at the code it looks like it is doing a pre-req check and trying to execute ant -version but failing. I then tried skipping that pre-req only for it to then error out when it tries to execute java -version. But after the cordova command errors out I can type ant -version and java -version and both commands execute successfully, see screenshot below.
I am running Windows 7 Pro 64bit and my path variables looks like this:
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_51
ANT_HOME = c:\apache-ant-1.9.3
PATH=C:\Program Files\nodejs;%ANDROID_HOME%;%ANDROID_TOOLS%;
C:\Users\Super\AppData\Roaming\npm;%JAVA_HOME%\bin;%ANT_HOME%\bin
Here is the screenshot from running the command with the -d option.
It turns out I must of accidently deleted c:\windows\system32 from the PATH variable and so it could not find the cmd command. Added the path c:\windows\system32 back in and I no longer receive the Ant error.

MATLAB code conversion to Java

I am trying to convert this code into Java Package using the MATLAB compiler and I'm getting this error on building. Can someone suggest anything?
'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.
Is there any specific command line to be included into the matlab function file (for example we include %#codegen for C/C++ conversion)
Make sure that you have the Java compiler installed. Try executing java -version and javac -version at a system prompt, and ensure that these both run and give a version that is supported by your version of MATLAB.
Check also that your system environment variables are set appropriately. In particular the JAVA_HOME variable should be set to your JDK path.

Categories

Resources