Linux_java calls the windows_matlab Program

Source: Internet
Author: User
0 description

In this paper, we conduct a detailed test and exploration to study the mixed programming of Java and MATLAB, so as to solve an application that Java programs call the MATLAB program in Linux.

 

Linux: (run the Java program and call the jar package file generated by MATLAB in Windows)

L Linux Ubuntu 3.5.0-17-generic

L Java version "1.6.0 _ 45"

L mcr_r2012a_glnx86_installer.zip

Windows environment: (debug the MATLAB program and use javabuilder to generate a jar package file called by Java)

L win7 x86 (32-bit)

L Java version "1.6.0 _ 27"

L MATLAB 2012a

L unlimited eclipse versions


(The 64-bit method is the same)

1. Install Vm and vmtool in win7

Install win7 (x86) 32-bit on the VM. Note that the processor is intel. (AMD processor requires special processing, which is omitted here)

2 install MATLAB in win7

7.14.0.739 (r2012a), virtual optical drive required.

Pay attention to standalone installation. You can refer to the install prompt in the crack path. After the installation is complete, import the certificate.

3. Check the required JDK version in MATLAB.

> Version-Java

Ans = Java 1.6.0 _ 17-b04 with Sun Microsystems Inc. Java hotspot (TM) Client VM Mixed Mode

4. Download and install JDK in win7

Http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download the current maximum version of 1.6

 

Configuration:

Create java_home JDK path

Create classpath.; % java_home % \ Lib \ tools. Jar

Create PATH % java_home % \ bin; % java_home % \ JRE \ bin;

 

Input in MATLAB! Javac verifies that JDK is successfully installed

5. Create a helloworld. M file using Matlab

Function helloworld

% CLC

Info = char ('matlab Hello world! ');

Disp (Info );

 

The input helloworld will be printed in MATLAB.

6. Create a Java project using Matlab

You can enter> deploytool on the console to call up Ja.

Add resources such as class and M, and press the compile button. It may take several minutes.


7. Test Java in win7 and call MATLAB

Create a test project in eclipse, and import the generated helloworld. jar and javabuilder. Jar (note the system version)

The test results are as follows:

8. Download and install MCR in Linux

(Linux 32-bit MCR x86 is selected here)

Http://www.mathworks.cn/products/compiler/mcr/index.html

 

Install MCR

Modify the installer_input.txt field, open the statement starting with #, and assign a value

Destinationfolder =/hadoop/MATLAB # modify the installation path

Agreetolicense = Yes

Fileinstallationkey = 38699-60149-36808-21840-05491

Licensepath =/home/hadoop/MCR/lic_standalone.dat

Outputfile =/home/hadoop/MCR/log/1.log# modify the Log Path

Mode = silent

And so on.

./Install-inputfile installer_input.txt (if not, use the root command for installation)

If the following prompt is displayed, the installation is successful.

(Jun 17,201 3 20:09:03) refreshing product list...

(Jun 17,201 3 20:09:16) the destination folder/hadoop/MATLAB does not exist. wocould you like to create it?

(Jun 17,201 3 20:09:17) Installing product: MATLAB compiler runtime 7.17

(Jun 17,201 3 20:11:12) Notes:

On the target computer, append the following to your LD_LIBRARY_PATH environment variable:

/Hadoop/Matlab/v717/runtime/glnx86:/hadoop/Matlab/v717/bin/glnx86:/hadoop/Matlab/v717/sys/OS/glnx86: /hadoop/Matlab/v717/sys/Java/JRE/glnx86/JRE/lib/i386/native_threads: /hadoop/Matlab/v717/sys/Java/JRE/glnx86/JRE/lib/i386/Server: /hadoop/Matlab/v717/sys/Java/JRE/glnx86/JRE/lib/i386

Next, set the xapplresdir environment variable to the following value:

/Hadoop/Matlab/v717/X11/APP-defaults

(Jun 17,201 3 20:11:12) exiting with status 0

(Jun 17,201 3 20:11:12) end-successful.

 

Download and install JDK

See http://developer.51cto.com/art/200907/135155.htm

Configure JDK and MCR

> VI. Profile

Export java_home =/hadoop/jdk1.6.0 _ 45

Export jre_home =/hadoop/jdk1.6.0 _ 45/JRE

Export classpath =.: $ java_home/lib: $ jre_home/lib: $ classpath

Export Path = $ java_home/bin: $ jre_home/bin: $ path

# These are JDK Environment Variables

Export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/hadoop/MCR/bin/glnx86/:/hadoop/Matlab/v717/runtime/glnx86:/hadoop/Matlab/v717/bin/glnx86: /hadoop/Matlab/v717/sys/OS/Gln

X86:/hadoop/Matlab/v717/sys/Java/JRE/glnx86/JRE/lib/i386/native_threads: /hadoop/Matlab/v717/sys/Java/JRE/glnx86/JRE/lib/i386/Server:/hadoop/Matlab/v717/sys/Java

/JRE/glnx86/JRE/lib/i386

Export xapplresdir = $ xapplresdir:/hadoop/Matlab/v717/X11/APP-defaults

# The following two environment variables are the configuration path of Matlab, which will be automatically prompted after installation of Matlab.

Other settings

VI ~ /. Bashrc

Alias MATLAB = '/usr/local/Matlab/maid/v717/bin/MATLAB'

If the libc. so.6 cannot be found by running the MATLAB command, sudo ln-S/lib/i386-linux-gnu/lib/libc. so.6

If you allow the MATLAB command to report the MATLAB: No MATLAB executable for this machine architecture. error,

Download Linux JDK x86 (32-bit)

Http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin? Authparam = 1371469475_8f7477cdc6c7ca6852a4cc44e7010c6c

9 Linux testing Java calls MATLAB

After you use eclipse fat-jar to package this, replace javabuilder in 7 with the JAR file in the javabuilder \ ja \ glnx86 path.

Successful.

 

At this point, the entire process of Java calling the MATLAB program is basically described.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.