| View previous topic :: View next topic |
| Author |
Message |
feasil General User

Joined: 07 Aug 2006 Posts: 16 Location: Clermont-Ferrand, France
|
Posted: Wed Aug 09, 2006 7:31 am Post subject: Use OOo with an independent Java program |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Wed Aug 09, 2006 12:55 pm Post subject: |
|
|
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 |
|
 |
feasil General User

Joined: 07 Aug 2006 Posts: 16 Location: Clermont-Ferrand, France
|
Posted: Wed Aug 09, 2006 11:11 pm Post subject: |
|
|
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 |
|
 |
feasil General User

Joined: 07 Aug 2006 Posts: 16 Location: Clermont-Ferrand, France
|
Posted: Wed Aug 09, 2006 11:18 pm Post subject: |
|
|
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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
feasil General User

Joined: 07 Aug 2006 Posts: 16 Location: Clermont-Ferrand, France
|
Posted: Thu Aug 10, 2006 6:01 am Post subject: |
|
|
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 |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3531 Location: Hamburg, Germany
|
Posted: Thu Aug 10, 2006 11:30 am Post subject: |
|
|
| 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 |
|
 |
feasil General User

Joined: 07 Aug 2006 Posts: 16 Location: Clermont-Ferrand, France
|
Posted: Fri Aug 11, 2006 3:44 am Post subject: |
|
|
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 |
|
 |
mnasato Power User

Joined: 26 Apr 2005 Posts: 54 Location: London, U.K.
|
Posted: Fri Aug 11, 2006 6:45 am Post subject: |
|
|
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 |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3531 Location: Hamburg, Germany
|
Posted: Sat Aug 12, 2006 5:14 am Post subject: |
|
|
| 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 |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3531 Location: Hamburg, Germany
|
Posted: Sat Aug 12, 2006 5:20 am Post subject: |
|
|
| 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 |
|
 |
|