Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
import java class

Subject: import java class

From: Robert

Date: 28 Jan, 2010 19:53:04

Message: 1 of 2

Problem: Matlab will not import a Java class

Details:
 Class XX was created in NetBeans 6.7.1 as part of a package YY

 YY compiles fine and runs under NetBeans

 Class XX has dependencies on three classes from two other libraries AA, BB
 
 I created a directory to hold my java classes that were to be used in Matlab ( .../Matlab /Jclasses )

 I made copies of the AA.jar, BB.jar, YY.jar and XX.class and placed them in directory .../Matlab/Jclasses
 
 I added .../Matlab/Jclasses to the dynamic path
 I added .../Matlab/Jclasses/AA.Jar to the dynamic path
 I added .../Matlab/Jclasses/BB.Jar to the dynamic path
 I added .../Matlab/Jclasses/YY.Jar to the dynamic path

 I ran import AA.SomeClass; That worked and I could create SomeClass
 I ran import BB.AnotherClass; That worked and I could create AnotherClass

 I ran import YY.MyClass; That did NOT work and matlab said YY.MyClass can not be found or can not be imported

 I ran import YY.*; That appears to work but if I try and create MyClass using
ZZ = MyClass or using ZZ = javaObect(YY.MyClass) or using ZZ = javaObect(MyClass) then matlab says "no class MyClass can be located on Java class path"



Does anyone have a suggestion as to why matlab will not import my class?

I using matlab version 7.6.0

Subject: import java class

From: Yair Altman

Date: 29 Jan, 2010 07:00:20

Message: 2 of 2

"Robert" <robert.clement.stopspam@ed.ac.uk> wrote in message <hjspv0$1r7$1@fred.mathworks.com>...
> Problem: Matlab will not import a Java class
>
> Details:
> Class XX was created in NetBeans 6.7.1 as part of a package YY
>
> YY compiles fine and runs under NetBeans
>
> Class XX has dependencies on three classes from two other libraries AA, BB
>
> I created a directory to hold my java classes that were to be used in Matlab ( .../Matlab /Jclasses )
>
> I made copies of the AA.jar, BB.jar, YY.jar and XX.class and placed them in directory .../Matlab/Jclasses
>
> I added .../Matlab/Jclasses to the dynamic path
> I added .../Matlab/Jclasses/AA.Jar to the dynamic path
> I added .../Matlab/Jclasses/BB.Jar to the dynamic path
> I added .../Matlab/Jclasses/YY.Jar to the dynamic path
>
> I ran import AA.SomeClass; That worked and I could create SomeClass
> I ran import BB.AnotherClass; That worked and I could create AnotherClass
>
> I ran import YY.MyClass; That did NOT work and matlab said YY.MyClass can not be found or can not be imported
>
> I ran import YY.*; That appears to work but if I try and create MyClass using
> ZZ = MyClass or using ZZ = javaObect(YY.MyClass) or using ZZ = javaObect(MyClass) then matlab says "no class MyClass can be located on Java class path"
>
> Does anyone have a suggestion as to why matlab will not import my class?
>
> I using matlab version 7.6.0

Try adding YY to the static path - the dynamic path is known to be problematic in some cases (possibly a classloader issue). You may perhaps need to restart Matlab.

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us