OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Use OOo with an independent Java program

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Wed Aug 09, 2006 7:31 am    Post subject: Use OOo with an independent Java program Reply with quote

Hello,

I would have wanted to create a java program which would be able to use OpenOffice (for Printing, ...).
After 3 days, I finally obtain anything and I am now able to launch OpenOffice from Java but I have now a new problem :
My program only works with jar included on openoffice directory (C:\Program Files\OpenOffice.org 2.0\program\classes) so I can't use it on another computer where Openoffice isn't installed in the same place.

I ever tried to copy this jars, but it doesn't work any more and it tell that it didn't find OpenOffice.

So If somebody knows how to do, please tell me !


I want to tell too that I am totally newbie in those technologies !


Thanks for helping me !
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3618
Location: Columbus, Ohio, USA

PostPosted: Wed Aug 09, 2006 12:55 pm    Post subject: Reply with quote

Disclaimer: I have never done this and I really know nothing about this.

I just wanted to be certain that I understand your problem.

1. You want to run your java program on a computer that does NOT have Ooo installed.

2. The Java program will connect to an instance of OOo running on another computer.

3. You want to know if this is possible, and if so, what files must be copied to the computer that runs your Java program.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Wed Aug 09, 2006 11:11 pm    Post subject: Reply with quote

First, thanks for your answer

And no, it's not what I wanted to tell, I'll try to better explain.

I have java pograms which work with openoffice's jars (and control it).
I tried to copy those jars out of openoffice's install directory and to link those ones from eclipe, but it didn't work anymore :
Code:
com.sun.star.comp.helper.BootstrapException: no office executable found!
   at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
   at TextReplace.getDesktop(TextReplace.java:168)
   at TextReplace.main(TextReplace.java:59)


On the other hand, when they are linked from openoffice's install directory, programs work without Exception !


I hope it's more clear than previous message.

Thanks for helping me !
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Wed Aug 09, 2006 11:18 pm    Post subject: Reply with quote

I forgotten to tell what I want to do :

I want to link jars from another directory than openoffice ones in order to make programs work one every machines where openoffice is install (as if it's not on 'C:\Program Files\OpenOffice.org 2.0\').
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Aug 10, 2006 5:19 am    Post subject: Reply with quote

First I am not a Java programmer.
It's probably because your jar file use other jar files and if you move it, it is unable to find them again.

You can retrieve where the OOo is installed with Windows registry. I have read that somewhere and I don't remember if it's in that thread :

get Value from windows registry http://www.oooforum.org/forum/viewtopic.phtml?t=19795
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Thu Aug 10, 2006 6:01 am    Post subject: Reply with quote

Thanks, but I tried to copy every jar in the same directory and it gives me the same error.

For getting value from windows registry, I'll try but I don't know if it's possible to change classpath on every launch of the program !


If anyone have an idea, thanks telling me !
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3531
Location: Hamburg, Germany

PostPosted: Thu Aug 10, 2006 11:30 am    Post subject: Reply with quote

feasil wrote:
I have java pograms which work with openoffice's jars (and control it).
I tried to copy those jars out of openoffice's install directory and to link those ones from eclipe, but it didn't work anymore :
Code:
com.sun.star.comp.helper.BootstrapException: no office executable found!
   at com.sun.star.comp.helper.Bootstrap.bootstrap(Bootstrap.java:253)
   at TextReplace.getDesktop(TextReplace.java:168)
   at TextReplace.main(TextReplace.java:59)


On the other hand, when they are linked from openoffice's install directory, programs work without Exception !

The problem is, that you use the Bootstrap mechanism. I experienced the same problem as a colleague of mine started using the Bootstrap mechanism.

Try the older OOo connection mechanism by making OOo listen on a specific report. This mechanism is no longer documented in the current version of the OOo Developer's Guide. But it still works. If you cannot find appropriate help for the older connection mechanism try to download an OOo 1.1.x SDK. That should contain it. And by using that connection mechanism you can put OOo's jar files somewhere in the CLASSPATH. I'm doing that myself on Windows XP, Solaris and Linux (Kanotix, a Dabian based Linux).

Another advantage of the older connection mechanism has been discussed recently in thsi thread: http://www.oooforum.org/forum/viewtopic.phtml?t=39950&highlight=connection. Try this thread http://www.oooforum.org/forum/viewtopic.phtml?t=29097 if you need some more Java code about the connection mechanism. And this thread for OOo's listen parameter http://www.oooforum.org/forum/viewtopic.phtml?t=19790.

With kind regards
hol.sten
Back to top
View user's profile Send private message
feasil
General User
General User


Joined: 07 Aug 2006
Posts: 16
Location: Clermont-Ferrand, France

PostPosted: Fri Aug 11, 2006 3:44 am    Post subject: Reply with quote

That works !

I did what you said hol.sten but with this solution, I had to launch soffice, so I used SergeM's idea and search in windows registry OpenOffice's Install directory.


So, thanks everybody
_________________
Sorry for my english !...
Back to top
View user's profile Send private message
mnasato
Power User
Power User


Joined: 26 Apr 2005
Posts: 54
Location: London, U.K.

PostPosted: Fri Aug 11, 2006 6:45 am    Post subject: Reply with quote

Being used to the old method of starting OOo in listening mode and then connecting to it from Java, I was curious to see how this new Bootstrap mechanism works without having to start OOo first.

Well, all it does is to start an OOo instance in listening mode in the good old fashion if one is not already running. For example the FirstUnoContact sample included in the new SDK creates a process like this
Code:

soffice -nologo -nodefault -norestore -nocrashreport -nolockcheck -accept=pipe,name=uno6074336316772990743;urp;

and it is left running after the Java program has exited.

I think this document details the reason for the new method

http://udk.openoffice.org/common/man/spec/transparentofficecomponents.html

While it may be easier to get started with, it's still good to understand the underlying accept/connect mechanism in case you run into issues (and you will, sooner or later). And starting the OOo service explicitly gives you more control.

So I agree with hol.sten that the old way is better than the new one. Additionally, anything that uses custom class loaders gives me the shivers.

Cheers

Mirko
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3531
Location: Hamburg, Germany

PostPosted: Sat Aug 12, 2006 5:14 am    Post subject: Reply with quote

feasil wrote:
I did what you said hol.sten but with this solution, I had to launch soffice

Sorry for not mentioning it in this thread, but you are right. You have to launch OOo or you have to let your Java application launch OOo. I'm using the second option. The advantage of this solution is, that it still works after OOo crashes, what happens from time to time. All my Java application has to do is to relauch OOo again.

feasil wrote:
so I used SergeM's idea and search in windows registry OpenOffice's Install directory.

So your solution will only work on Windows.

With kind regards
hol.sten
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3531
Location: Hamburg, Germany

PostPosted: Sat Aug 12, 2006 5:20 am    Post subject: Reply with quote

mnasato wrote:
And starting the OOo service explicitly gives you more control.

And that is what you need if you need a solution that even works on a server which runs all day long.

mnasato wrote:
Additionally, anything that uses custom class loaders gives me the shivers.

Full ACK!

With kind regards
hol.sten
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group