Thread Subject: Problem with calling / importing JAVA class

Subject: Problem with calling / importing JAVA class

From: Sebastian Hölz

Date: 22 Nov, 2011 16:45:09

Message: 1 of 5

Hi,

I'm trying to import a java-class, which is sitting in a jar-file and fail miserably. Here is what I'm doing:

>> javaaddpath('d:\Matlab\JAVA\ODF_DOM\simple-odf-0.6.6.jar', '-end')
>> import org.odftoolkit.simple.*;

>> doc = SpreadsheetDocument.loadDocument('Test.ods');

The last call fails with ...
Undefined variable "SpreadsheetDocument" or class "SpreadsheetDocument.loadDocument".

I checked the following:
- The jar-file is sitting in the specified directory
- using "javaclasspath" I can see that the path was added tot he dynamic java path,
- browsing the archive I can see the "SpreadsheetDocument.class" file sitting in the (zipped) directory "org.odftoolkit.simple".

What am I missing?

Thanks

Sebastian

Subject: Problem with calling / importing JAVA class

From: ade77

Date: 22 Nov, 2011 18:14:09

Message: 2 of 5

"Sebastian Hölz" wrote in message <jagjil$787$1@newscl01ah.mathworks.com>...
> Hi,
>
> I'm trying to import a java-class, which is sitting in a jar-file and fail miserably. Here is what I'm doing:
>
> >> javaaddpath('d:\Matlab\JAVA\ODF_DOM\simple-odf-0.6.6.jar', '-end')
> >> import org.odftoolkit.simple.*;
>
> >> doc = SpreadsheetDocument.loadDocument('Test.ods');
>
> The last call fails with ...
> Undefined variable "SpreadsheetDocument" or class "SpreadsheetDocument.loadDocument".
>
> I checked the following:
> - The jar-file is sitting in the specified directory
> - using "javaclasspath" I can see that the path was added tot he dynamic java path,
> - browsing the archive I can see the "SpreadsheetDocument.class" file sitting in the (zipped) directory "org.odftoolkit.simple".
>
> What am I missing?
>
> Thanks
>
> Sebastian

don't forget to use "clear java" or restart matlab(not necessary if u clear)....
u might also consider using static path for faster loading.

Subject: Problem with calling / importing JAVA class

From: Sebastian Hölz

Date: 22 Nov, 2011 22:25:10

Message: 3 of 5

Why would I use "clear java" ?!

Sebastian

Subject: Problem with calling / importing JAVA class

From: ade77

Date: 23 Nov, 2011 14:59:10

Message: 4 of 5

"Sebastian Hölz" wrote in message <jah7g6$h1k$1@newscl01ah.mathworks.com>...
> Why would I use "clear java" ?!
>
> Sebastian

the documentation on adding java classes into MATLAB clearly states that if you are using static path, you must restart MATLAB, and if you are using dynamic path, you must refresh MATLAB. The only way to refresh MATLAB in this specific instance is either to use "clear java" at the command prompt or restart MATLAB.

I would advise if u are still having problem to use the static method, which is more stable.

Subject: Problem with calling / importing JAVA class

From: Sebastian Hölz

Date: 24 Nov, 2011 08:42:08

Message: 5 of 5

Problem resolved,

the jar-archive had some dependencies on a second archive, which also needed to be added to the path. This was not clear from the documentation, but I figured it out after a while.

Thanks

Sebastian

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
java Sebastian Hölz 22 Nov, 2011 11:49:12
rssFeed for this Thread

Contact us at files@mathworks.com