UNO Boostrap anomalies

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

UNO Boostrap anomalies

Stadler Hans-Christian
Hi,

I have a test program written in Java to access OpenOffice functionality through UNO.
The program works fine except if it is packed into a jar file.

Running the program directly:

[stadler_h@pc5443 bin]$ ls -R
.:
TextExtractor.class
[stadler_h@pc5443 bin]$ java -classpath .:/opt/openoffice.org2.0/program/classes/unoloader.jar:/opt/openoffice.org2.0/program/classes/unoil.jar:/opt/openoffice.org2.0/program/classes/jurt.jar:/opt/openoffice.org2.0/program/classes/ridl.jar:/opt/openoffice.org2.0/program/classes/juh.jar TextExtractor /tmp/test.xls
Established connecttion to OpenOffice
...

Running the program from the jar file:

[stadler_h@pc5443 OOUno]$ jar cmf MANIFEST.MF oouno.jar -C bin TextExtractor.class
[stadler_h@pc5443 OOUno]$ jar tf oouno.jar
META-INF/
META-INF/MANIFEST.MF
TextExtractor.class
[stadler_h@pc5443 OOUno]$ jar xf oouno.jar META-INF/MANIFEST.MF; cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Class-Path: /opt/openoffice.org2.0/program/classes/unoloader.jar /opt/
 openoffice.org2.0/program/classes/juh.jar /opt/openoffice.org2.0/prog
 ram/classes/jurt.jar /opt/openoffice.org2.0/program/classes/ridl.jar
 /opt/openoffice.org2.0/program/classes/unoil.jar
Created-By: 1.5.0_06 (Sun Microsystems Inc.)
Main-Class: TextExtractor
[stadler_h@pc5443 OOUno]$ java -jar oouno.jar /tmp/test.xls
com.sun.star.comp.helper.BootstrapException: no office executable found!
        at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
        at TextExtractor.main(TextExtractor.java:89)

Following suggestions from this thread I have tried to use the UnoClassLoader and give some extra arguments, but nothing works:

[stadler_h@pc5443 OOUno]$ java -Dcom.sun.star.lib.loader.unopath="/opt/openoffice.org2.0/program" -classpath .:/opt/openoffice.org2.0/program/classes/unoloader.jar:/opt/openoffice.org2.0/program/classes/unoil.jar:/opt/openoffice.org2.0/program/classes/jurt.jar:/opt/openoffice.org2.0/program/classes/ridl.jar:/opt/openoffice.org2.0/program/classes/juh.jar:/opt/openoffice.org2.0/program -jar oouno.jar /tmp/test.xls
com.sun.star.comp.helper.BootstrapException: no office executable found!
        at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
        at TextExtractor.main(TextExtractor.java:89)

Is there a way to allow for packing the client into a jar file and at the same time using the simple bootstrap method?

Sincerely,
Hans-Christian Stadler
--------------------------------------

        public static void main(String[] args) {
        try {
        // use uno class loader
        File oobase = new File("/opt/openoffice.org2.0/program");
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        ClassLoader unoClassLoader = new UnoClassLoader(oobase.toURL(), classLoader);
        Thread.currentThread().setContextClassLoader(unoClassLoader);
      // get the office context
        XComponentContext xContext = Bootstrap.bootstrap();
            assert(xContext.getClass().getClassLoader() == unoClassLoader);
            System.out.println("Established connecttion to OpenOffice");
            XMultiComponentFactory xMCF = xContext.getServiceManager();
                ....
        }
        catch (java.lang.Exception e){
            e.printStackTrace();
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: UNO Boostrap anomalies

Cédric Bosdonnat
Hi Hans-Christian,

Stadler Hans-Christian a écrit :

> Running the program from the jar file:
>
> [stadler_h@pc5443 OOUno]$ jar cmf MANIFEST.MF oouno.jar -C bin TextExtractor.class
> [stadler_h@pc5443 OOUno]$ jar tf oouno.jar
> META-INF/
> META-INF/MANIFEST.MF
> TextExtractor.class
> [stadler_h@pc5443 OOUno]$ jar xf oouno.jar META-INF/MANIFEST.MF; cat META-INF/MANIFEST.MF
> Manifest-Version: 1.0
> Class-Path: /opt/openoffice.org2.0/program/classes/unoloader.jar /opt/
>  openoffice.org2.0/program/classes/juh.jar /opt/openoffice.org2.0/prog
>  ram/classes/jurt.jar /opt/openoffice.org2.0/program/classes/ridl.jar
>  /opt/openoffice.org2.0/program/classes/unoil.jar
> Created-By: 1.5.0_06 (Sun Microsystems Inc.)
> Main-Class: TextExtractor
> [stadler_h@pc5443 OOUno]$ java -jar oouno.jar /tmp/test.xls
> com.sun.star.comp.helper.BootstrapException: no office executable found!
>         at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
>         at TextExtractor.main(TextExtractor.java:89)

Did you put the juh.jar file in your jar ? juh.jar needs some OOo C++
libraries and the soffice program in its program. You would better pack
your classes into a jar (eg: test.jar) and then add it to your
classpasth with the OOo jars.

If you want to make this easier, you can use some shell scripts to avoid
 long commands typing.

> Following suggestions from this thread I have tried to use the UnoClassLoader and give some extra arguments, but nothing works:

I haven't see there already was a UnoClassLoader: I'll better have to
use it instead of rewriting it: thanks for the idea ;)

Hope that helps,
Cedric

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: UNO Boostrap anomalies

Stadler Hans-Christian
> Did you put the juh.jar file in your jar ?
No, I only give the external path to the juh.jar file in the manifest.

> juh.jar needs some OOo C++ libraries and the soffice program in its program.
Yes, setting LD_LIBRARY_PATH doesn't work either:
[stadler_h@pc5443 OOUno]$ LD_LIBRARY_PATH=/opt/openoffice.org2.0/program java -Dcom.sun.star.lib.loader.unopath="/opt/openoffice.org2.0/program" -classpath .:/opt/openoffice.org2.0/program/classes/unoloader.jar:/opt/openoffice.org2.0/program/classes/unoil.jar:/opt/openoffice.org2.0/program/classes/jurt.jar:/opt/openoffice.org2.0/program/classes/ridl.jar:/opt/openoffice.org2.0/program/classes/juh.jar:/opt/openoffice.org2.0/program -jar oouno.jar /tmp/test.xls
com.sun.star.comp.helper.BootstrapException: no office executable found!
        at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
        at TextExtractor.main(TextExtractor.java:89)



> You would better pack
> your classes into a jar (eg: test.jar) and then add it to your
> classpasth with the OOo jars.
That's exactly what I did.

HC

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: UNO Boostrap anomalies

Juergen Schmidt-3
In reply to this post by Stadler Hans-Christian
Cedric Bosdonnat wrote:

> Hi Hans-Christian,
>
> Stadler Hans-Christian a écrit :
>
>> Running the program from the jar file:
>>
>> [stadler_h@pc5443 OOUno]$ jar cmf MANIFEST.MF oouno.jar -C bin TextExtractor.class
>> [stadler_h@pc5443 OOUno]$ jar tf oouno.jar
>> META-INF/
>> META-INF/MANIFEST.MF
>> TextExtractor.class
>> [stadler_h@pc5443 OOUno]$ jar xf oouno.jar META-INF/MANIFEST.MF; cat META-INF/MANIFEST.MF
>> Manifest-Version: 1.0
>> Class-Path: /opt/openoffice.org2.0/program/classes/unoloader.jar /opt/
>>  openoffice.org2.0/program/classes/juh.jar /opt/openoffice.org2.0/prog
>>  ram/classes/jurt.jar /opt/openoffice.org2.0/program/classes/ridl.jar
>>  /opt/openoffice.org2.0/program/classes/unoil.jar

The Class-Path option in a manifest file works only with relative paths.
   But you don't need it here. Using the simple bootstrap mechanism
(described bellow) does it for, internally an own classloader is used to
provide all necessary UNO types from the office.

>> Created-By: 1.5.0_06 (Sun Microsystems Inc.)
>> Main-Class: TextExtractor
>> [stadler_h@pc5443 OOUno]$ java -jar oouno.jar /tmp/test.xls
>> com.sun.star.comp.helper.BootstrapException: no office executable found!
>>         at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
>>         at TextExtractor.main(TextExtractor.java:89)
>
> Did you put the juh.jar file in your jar ? juh.jar needs some OOo C++

wait, you don't need to put juh.jar in your jar.
The SDK contains some glue code which should be integrated in your jar
file to use the simple bootstrap mechanism. Furthermore you have to
modify your manifest file.

Add the following classes (<sdk>/classes) from the SDK to your jar:
com/sun/star/lib/loader/Loader$CustomURLClassLoader.class
com/sun/star/lib/loader/Loader.class
com/sun/star/lib/loader/InstallationFinder$StreamGobbler.class
com/sun/star/lib/loader/InstallationFinder.class
com/sun/star/lib/loader/WinRegKey.class
com/sun/star/lib/loader/WinRegKeyException.class
win/unowinreg.dll

Modify your manifest:
Main-Class: com.sun.star.lib.loader.Loader

Name: com/sun/star/lib/loader/Loader.class
Application-Class: TextExtractor

To ensure that a preferred office installation is used you can run your
application with
java -Dcom.sun.star.lib.loader.unopath=<office_program_path> -jar oouno.jar

If you don't use the -D option the default office is used. But this
works only with an office donwloaded from OpenOffice.org (or a mirror)
directly. On some Linux distros you can have problems with the office
found in /usr/bin or some where else in the PATH.

Juergen




> libraries and the soffice program in its program. You would better pack
> your classes into a jar (eg: test.jar) and then add it to your
> classpasth with the OOo jars.
>
> If you want to make this easier, you can use some shell scripts to avoid
>  long commands typing.
>
>> Following suggestions from this thread I have tried to use the UnoClassLoader and give some extra arguments, but nothing works:
>
> I haven't see there already was a UnoClassLoader: I'll better have to
> use it instead of rewriting it: thanks for the idea ;)
>
> Hope that helps,
> Cedric
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]