Thread Subject: Calling java within a Matlab task

Subject: Calling java within a Matlab task

From: jjcahill@gmail.com

Date: 23 May, 2009 07:22:21

Message: 1 of 6

Hi,

I have a simple java call within a Matlab task but the java function
isn't recognized. It appears java doesn't work in tasks.

The java function, which resides in a jar file on the Matlab java
path, is normally accessible from the command line using a fully
qualified name, or using an import statement and class name. The
pathDependencies option for createJob in which the task runs doesn't
seem to help with java dependencies.

A search for messages on this topic didn't turn up anything at all.

Can anyone confirm that java is not supported in tasks? It seems
likely this is the case, but is surprising given that java seems
tightly integrated with Matlab.

Thanks

Josh

Subject: Calling java within a Matlab task

From: Yair Altman

Date: 23 May, 2009 20:03:02

Message: 2 of 6

jjcahill@gmail.com wrote in message <53759309-83b6-4c56-af25-1ee6383b2940@a5g2000pre.googlegroups.com>...
> Hi,
>
> I have a simple java call within a Matlab task but the java function
> isn't recognized. It appears java doesn't work in tasks.
>
> The java function, which resides in a jar file on the Matlab java
> path, is normally accessible from the command line using a fully
> qualified name, or using an import statement and class name. The
> pathDependencies option for createJob in which the task runs doesn't
> seem to help with java dependencies.
>
> A search for messages on this topic didn't turn up anything at all.
>
> Can anyone confirm that java is not supported in tasks? It seems
> likely this is the case, but is surprising given that java seems
> tightly integrated with Matlab.
>
> Thanks
>
> Josh


You can test this by simply calling java.lang.String('abc') from within your Matlab task. If it works then you probably have a problem with your javaclasspath (which the javaclasspath function will probably fix); if not then you're stuck... Please post your findings here for others to benefit.

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Calling java within a Matlab task

From: Steven Lord

Date: 24 May, 2009 02:23:25

Message: 3 of 6


<jjcahill@gmail.com> wrote in message
news:53759309-83b6-4c56-af25-1ee6383b2940@a5g2000pre.googlegroups.com...
> Hi,
>
> I have a simple java call within a Matlab task but the java function
> isn't recognized. It appears java doesn't work in tasks.
>
> The java function, which resides in a jar file on the Matlab java
> path, is normally accessible from the command line using a fully
> qualified name, or using an import statement and class name. The
> pathDependencies option for createJob in which the task runs doesn't
> seem to help with java dependencies.
>
> A search for messages on this topic didn't turn up anything at all.
>
> Can anyone confirm that java is not supported in tasks? It seems
> likely this is the case, but is surprising given that java seems
> tightly integrated with Matlab.

As far as I know calls to Java should work within tasks of a job. Keep in
mind that tasks run in separate MATLAB sessions (the workers) so if you
needed to do anything (modifying the class path, IMPORTing the class, etc.)
to get the Java call to work on your client, you'll need to perform those
same steps on the workers to get it to work on them.

--
Steve Lord
slord@mathworks.com

Subject: Calling java within a Matlab task

From: jjcahill@gmail.com

Date: 24 May, 2009 04:12:08

Message: 4 of 6

Apologies for jumping to too broad a conclusion that java may not be
supported. I tried the java.lang.string call within the task and that
did work. It was also possible to access the jar file by modifying
the java class path within the task using javaaddpath as suggested.
This wasn't tried immediately as I assumed this sort of information
would be provided in the call to createJob using one of the dependency
parameters.

Thanks for your help. It has saved an embarrasingly and
inconveniently parallel situation of running multiple instances of
Matlab instead to achieve similar effect.

Josh

Subject: Calling java within a Matlab task

From: Raymond Norris

Date: 26 May, 2009 14:37:00

Message: 5 of 6

Hi Josh,

The MATLAB Workers do load some parts of Java. To verify what is supported, try running the following checker:

function pctCheckJavaSupport()

sched = findResource;
job = sched.createJob();
job.createTask(@javachk,1,{{'awt','AWT'},{'desktop','MATLAB Desktop'}, ...
   {'jvm','jvm'},{'swing','Java Swing'}});

job.submit
job.waitForState('finished')

em = job.getAllOutputArguments();
for eidx = 1:length(em)
   if isempty(em{eidx})==false
      display(em{eidx}.message)
   end
end

end

You'll notice that Java Swing is not supported, so the following call in your task function will fail:

   jf = javax.swing.JFrame('myapp');

But since the JVM is loaded, the following will work:

   s = java.lang.String('myapp');

Raymond


jjcahill@gmail.com wrote in message <53759309-83b6-4c56-af25-1ee6383b2940@a5g2000pre.googlegroups.com>...
> Hi,
>
> I have a simple java call within a Matlab task but the java function
> isn't recognized. It appears java doesn't work in tasks.
>
> The java function, which resides in a jar file on the Matlab java
> path, is normally accessible from the command line using a fully
> qualified name, or using an import statement and class name. The
> pathDependencies option for createJob in which the task runs doesn't
> seem to help with java dependencies.
>
> A search for messages on this topic didn't turn up anything at all.
>
> Can anyone confirm that java is not supported in tasks? It seems
> likely this is the case, but is surprising given that java seems
> tightly integrated with Matlab.
>
> Thanks
>
> Josh

Subject: Calling java within a Matlab task

From: Jaspar Cahill

Date: 16 Jun, 2009 00:12:05

Message: 6 of 6

On May 27, 12:37 am, "Raymond Norris" <raymond.nor...@mathworks.com>
wrote:
> Hi Josh,
>
> The MATLAB Workers do load some parts of Java.  To verify what is supported, try running the following checker:
>
> function pctCheckJavaSupport()
>
> sched = findResource;
> job = sched.createJob();
> job.createTask(@javachk,1,{{'awt','AWT'},{'desktop','MATLAB Desktop'}, ...
>    {'jvm','jvm'},{'swing','Java Swing'}});
>
> job.submit
> job.waitForState('finished')
>
> em = job.getAllOutputArguments();
> for eidx = 1:length(em)
>    if isempty(em{eidx})==false
>       display(em{eidx}.message)
>    end
> end
>
> end
>
> You'll notice that Java Swing is not supported, so the following call in your task function will fail:
>
>    jf = javax.swing.JFrame('myapp');
>
> But since the JVM is loaded, the following will work:
>
>    s = java.lang.String('myapp');
>
> Raymond
>
>
>
> jjcah...@gmail.com wrote in message <53759309-83b6-4c56-af25-1ee6383b2...@a5g2000pre.googlegroups.com>...
> > Hi,
>
> > I have a simple java call within a Matlab task but the java function
> > isn't recognized. It appears java doesn't work in tasks.
>
> > The java function, which resides in a jar file on the Matlab java
> > path, is normally accessible from the command line using a fully
> > qualified name, or using an import statement and class name.  The
> > pathDependencies option for createJob in which the task runs doesn't
> > seem to help with java dependencies.
>
> > A search for messages on this topic didn't turn up anything at all.
>
> > Can anyone confirm that java is not supported in tasks?  It seems
> > likely this is the case, but is surprising given that java seems
> > tightly integrated with Matlab.
>
> > Thanks
>
> > Josh

Thanks for the suggestion, and pardon the late response.

Fortunately I haven't a need to use Swing components in a task
presently, but good to know.

Josh

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
workers paralle... Raymond Norris 26 May, 2009 10:39:10
java Yair Altman 23 May, 2009 16:04:18
rssFeed for this Thread

Contact us at files@mathworks.com