Create a Java Package with MATLAB Code Error

I follow the following example:
In this step,
Compile the Java application using javac.
javac -classpath "mcrroot\toolbox\javabuilder\jar\javabuilder.jar";.\makesqr.jar .\getmagic.java
The cmd prompted the error :
.\getmagic.java:4: error: error while writing getmagic: C:\Program Files\makesqr\application\getmagic.class class getmagic ^ 1 error

 Accepted Answer

This is due to file access permissions. In my case, I got the following error.
C:\Program Files\makesqr\application>javac -classpath "C:\MATLAB\MATLAB_Runtime\v94\toolbox\javabuilder\jar\javabuilder.jar";.\makesqr.jar .\getmagic.java
.\getmagic.java:4: error: error while writing getmagic: .\getmagic.class (Access is denied)
class getmagic
^
1 error
javac tries to create getmagic.class file, but normal users do not have a permission to write a file under C:\Program Files.
I think there are two options.
  1. Launch command prompt as Administrator, then execute the javac command.
  2. Install makesqr package in another folder where normal users have a permission to write

6 Comments

On my system it is saying
error: file not found: .\getmagic.java
Please tell me why?
getmagic.java is to be created by yourself. In documentation of R2018b or earlier, you can find getmagic.java sample in "Java Code to Implement Application".
https://www.mathworks.com/help/releases/R2018b/compiler_sdk/gs/create-a-java-application-with-matlab-code.html
From R2019a, the java code is included in for_redistribution_files_only\samples folder.
Thank you for the reply, I have followed the process given in the link.
While installing MaAppInstaller_mcr.exe following error occurs :
Internal error: Failed to initialize application installer (204)
I am using MATLAB 2018a.
I am using matlab 2018a. After following the full process of following link
in the last step of executing following command ->
F:\makesqr\for_redistribution_files_only>java -classpath .;"C:\Program Files\MAT
LAB\MATLAB Runtime\v94\toolbox\javabuilder\jar\javabuilder.jar";.\makesqr.jar ge
tmagic 5
this error is generated ->
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: getmagic has
been compiled by a more recent version of the Java Runtime (class file version 5
5.0), this version of the Java Runtime only recognizes class file versions up to
52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
How this error can be resolved?
The class file version is 55.0, so I guess you have compiled getmagic.java by Java 11.
JVM in MATLAB R2018a (MATLAB Runtime v94) is Java 1.8.0_144, so you need to do javac by Java 8.
Thank you very much...It worked...

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!