Hi everyone,
I've been having an ongoing problem with bringing my java
classes into MatLab.
First of all, I created my class "Test" (part of the MLT
package) in eclipse with Java 1.5.
Then I jar'd it into myTest.jar, specifying the main class
in the manifest.
I then added this myTest.jar to the dynamic classpath using
"javaaddpath('/.../myTest.jar')" When I check the classpath
I can see it listed.
At this point I should be able to use the methods of the
class right? But when I type "methodsview MLT.Test" to see
the methods I get:
>> methodsview MLT.Test
??? Error using ==> methodsview
No class MLT.Test can be located or no methods for class
MLT.Test
Similarly:
>> methodsview Test
??? Error using ==> methodsview
No class Test can be located or no methods for class Test
Anybody have ANY idea what's going on? Matlab is running
Java 1.5, I've compiled it in 1.5, I've specified the path.
Am I missing something? The MathWorks help pages seem pretty
sparse in this area...
Any help would be great,
Craig
Craig,
You've already overcome (from what I've seen) the most common problem in
using Java from within MATLAB; you've got the packaging right. That is,
you put the class within a package, then tried to access it using
packagename.classname syntax.
Here are the next things that I would try, if I were you:
(1) Try using an absolute path in your javaaddpath() call, rather than a
relative path. The Java runtime "fixes" the current working directory (and
therefore the meaning of ./, ../, etc.) when it is launched. We can't make
it "follow MATLAB's current working directory." Therefore, "../" might not
mean what you think it means. Specify the path in full and see if that
solves the problem.
(2) Does the class that you compiled depend on other classes or packages
that you HAVEN'T added to MATLAB's javaclasspath? If so, the class loader
fails. Java doesn't tell MATLAB that the class failed to load because
soemthing that it depends on failed to load; it just tells MATLAB the class
couldn't be loaded properly. THAT could be the cause of the error.
(2a) I don't know what version of Java your version of MATLAB is running,
but if there's major "version skew," MATLAB's JVM might not be able to run
your class. Run
>> version -java
and see what it tells you. If it isn't 1.5 or later, that could be a
problem.
Hope this helps,
--
Bob Gilmore, The MathWorks, Inc.
"Craig " <craig@mathworks.com> wrote in message
news:fig0sa$b3i$1@fred.mathworks.com...
> Hi everyone,
> I've been having an ongoing problem with bringing my java
> classes into MatLab.
> First of all, I created my class "Test" (part of the MLT
> package) in eclipse with Java 1.5.
> Then I jar'd it into myTest.jar, specifying the main class
> in the manifest.
> I then added this myTest.jar to the dynamic classpath using
> "javaaddpath('/.../myTest.jar')" When I check the classpath
> I can see it listed.
>
> At this point I should be able to use the methods of the
> class right? But when I type "methodsview MLT.Test" to see
> the methods I get:
>
>>> methodsview MLT.Test
> ??? Error using ==> methodsview
> No class MLT.Test can be located or no methods for class
> MLT.Test
>
> Similarly:
>
>>> methodsview Test
> ??? Error using ==> methodsview
> No class Test can be located or no methods for class Test
>
> Anybody have ANY idea what's going on? Matlab is running
> Java 1.5, I've compiled it in 1.5, I've specified the path.
> Am I missing something? The MathWorks help pages seem pretty
> sparse in this area...
> Any help would be great,
> Craig
"Bob Gilmore" <bgilmore@mathworks.com> wrote in message
<fig9ri$ge8$1@fred.mathworks.com>...
> Craig,
> You've already overcome (from what I've seen) the most
common problem in
> using Java from within MATLAB; you've got the packaging
right. That is,
> you put the class within a package, then tried to access
it using
> packagename.classname syntax.
>
> Here are the next things that I would try, if I were you:
> (1) Try using an absolute path in your javaaddpath() call,
rather than a
> relative path. The Java runtime "fixes" the current
working directory (and
> therefore the meaning of ./, ../, etc.) when it is
launched. We can't make
> it "follow MATLAB's current working directory."
Therefore, "../" might not
> mean what you think it means. Specify the path in full
and see if that
> solves the problem.
> (2) Does the class that you compiled depend on other
classes or packages
> that you HAVEN'T added to MATLAB's javaclasspath? If so,
the class loader
> fails. Java doesn't tell MATLAB that the class failed to
load because
> soemthing that it depends on failed to load; it just tells
MATLAB the class
> couldn't be loaded properly. THAT could be the cause of
the error.
> (2a) I don't know what version of Java your version of
MATLAB is running,
> but if there's major "version skew," MATLAB's JVM might
not be able to run
> your class. Run
> >> version -java
> and see what it tells you. If it isn't 1.5 or later, that
could be a
> problem.
>
> Hope this helps,
> --
> Bob Gilmore, The MathWorks, Inc.
>
> "Craig " <craig@mathworks.com> wrote in message
> news:fig0sa$b3i$1@fred.mathworks.com...
> > Hi everyone,
> > I've been having an ongoing problem with bringing my java
> > classes into MatLab.
> > First of all, I created my class "Test" (part of the MLT
> > package) in eclipse with Java 1.5.
> > Then I jar'd it into myTest.jar, specifying the main class
> > in the manifest.
> > I then added this myTest.jar to the dynamic classpath using
> > "javaaddpath('/.../myTest.jar')" When I check the classpath
> > I can see it listed.
> >
> > At this point I should be able to use the methods of the
> > class right? But when I type "methodsview MLT.Test" to see
> > the methods I get:
> >
> >>> methodsview MLT.Test
> > ??? Error using ==> methodsview
> > No class MLT.Test can be located or no methods for class
> > MLT.Test
You should also check that your Test class and relevant
methods were declared public.
Thanks a lot Bob!
The problem was the path name. I'm running Matlab remotely
and I didn't upload the jar's to the server.
I can see the methods for this tester class now. Which is
step in the right direction.
Do you happen to know how well Java 1.6 is 'meshed' with
Matlab running a 1.6?
I have a GUI I'm almost done developing in NetBeans and I'd
like to be able to import it to Matlab with minimal hassels
so I can use MatLab to crunch some numbers for me.
Is this possible? Should I have designed this in Matlab from
the start? I really like the look/feel of java GUI's so I'd
prefer not to write the whole thing over again.
Your two cents worth on this situation would be VERY much
appreciated.
Thanks
Craig
"Bob Gilmore" <bgilmore@mathworks.com> wrote in message
<fig9ri$ge8$1@fred.mathworks.com>...
> Craig,
> You've already overcome (from what I've seen) the most
common problem in
> using Java from within MATLAB; you've got the packaging
right. That is,
> you put the class within a package, then tried to access
it using
> packagename.classname syntax.
>
> Here are the next things that I would try, if I were you:
> (1) Try using an absolute path in your javaaddpath() call,
rather than a
> relative path. The Java runtime "fixes" the current
working directory (and
> therefore the meaning of ./, ../, etc.) when it is
launched. We can't make
> it "follow MATLAB's current working directory."
Therefore, "../" might not
> mean what you think it means. Specify the path in full
and see if that
> solves the problem.
> (2) Does the class that you compiled depend on other
classes or packages
> that you HAVEN'T added to MATLAB's javaclasspath? If so,
the class loader
> fails. Java doesn't tell MATLAB that the class failed to
load because
> soemthing that it depends on failed to load; it just tells
MATLAB the class
> couldn't be loaded properly. THAT could be the cause of
the error.
> (2a) I don't know what version of Java your version of
MATLAB is running,
> but if there's major "version skew," MATLAB's JVM might
not be able to run
> your class. Run
> >> version -java
> and see what it tells you. If it isn't 1.5 or later, that
could be a
> problem.
>
> Hope this helps,
> --
> Bob Gilmore, The MathWorks, Inc.
>
> "Craig " <craig@mathworks.com> wrote in message
> news:fig0sa$b3i$1@fred.mathworks.com...
> > Hi everyone,
> > I've been having an ongoing problem with bringing my java
> > classes into MatLab.
> > First of all, I created my class "Test" (part of the MLT
> > package) in eclipse with Java 1.5.
> > Then I jar'd it into myTest.jar, specifying the main class
> > in the manifest.
> > I then added this myTest.jar to the dynamic classpath using
> > "javaaddpath('/.../myTest.jar')" When I check the classpath
> > I can see it listed.
> >
> > At this point I should be able to use the methods of the
> > class right? But when I type "methodsview MLT.Test" to see
> > the methods I get:
> >
> >>> methodsview MLT.Test
> > ??? Error using ==> methodsview
> > No class MLT.Test can be located or no methods for class
> > MLT.Test
> >
> > Similarly:
> >
> >>> methodsview Test
> > ??? Error using ==> methodsview
> > No class Test can be located or no methods for class Test
> >
> > Anybody have ANY idea what's going on? Matlab is running
> > Java 1.5, I've compiled it in 1.5, I've specified the path.
> > Am I missing something? The MathWorks help pages seem pretty
> > sparse in this area...
> > Any help would be great,
> > Craig
>
>
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.