Wednesday, July 16, 2014

How to start and configure web application developement with Matlab

Matlab has a feature to create web application. For people who are trying this feature for the first time to make the feature work can be quite confusing. How this matlab web application development feature works is that the Matlab code are converted to java code(java class strickly speaking) by Matlab Builder JA. Malab Builder JA is smaller and essential part for the conversion. The overall conversion of matlab code to web is through the Java application package creation which contains java components of all matlab code of your project and required components. Java package is created using the Library Compiler.

In order to use Matlab for web application deployment you need Java Development Kit(JDK). So the first thing to do is find the compatible version of the JDK that you have to download and install for your computer.

Enter the following matlab command to know which version of JDK you need,
!java- version


In matlab command window it looks like this if you did install version 1.7,
>> !java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b14)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode, sharing) 
Once you know this you should download that version of JDK.

Alternatively, you can also visit the following matlab page where you can see what version of different compilers and third party tools you requires according to the Matlab version you are using.

Assuming that you are using Matlab 2014a then the following url provides the information about the JDK version you need.

http://www.mathworks.com/support/compilers/R2014a/index.html

There you can see what Java JDK version you need as shown below
Choosing JDK version for matlab web developement
Choosing JDK version for matlab web developement

The figure shows that Matlab 2014a requires Java Development Kit(JDK) 1.7. So go to the Java website and download it. On the Java website it is listed as Java v7 which might cause confusion because it means the JDK v1.7.

Once you have download and installed the correct JDK you need to next set the JAVA_HOME environment variable path to the directory where you installed the JDK,something like C:\Program Files\Java\jdk1.7.0_65 so that Matlab knows and applies the java function. If this is not set then during the java package compilation you may get error.

Assuming you know how to set system environment variable, below is a screenshot of how it looks like,

setting JAVA_HOME environmental variable
setting JAVA_HOME environmental variable

That it, now you should be able to convert the matlab m code or GUI to Java Package using the Library Compiler. the Libary compiler is shown below. In the library compiler you select the Java Package in the application type and also select the matlab file to be exported.

Using Java Package Compiler in Matlab
Using Java Package Compiler in Matlab

The process of conversion produces three folders as follows,

for_redistribution — A folder containing the installer to distribute the package
for_testing — A folder containing the raw generated files to create the installer
for_redistribution_files_only — A folder containing only the files needed to redistribute the package
PackagingLog.txt — A log file generated by the compiler

Then one can check whether the produced java application is successful using the following command in the matlab command window,

 java -classpath "matlabroot\toolbox\javabuilder\jar\javabuilder.jar";<file_name>.jar <file-name>.Class1 5

See matlab tutorials page for more tutorials


No comments:

Post a Comment