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

Using Java with OOo
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Thu Mar 02, 2006 7:04 am    Post subject: Using Java with OOo Reply with quote

Well first off let me say that I am a newbie when it comes to using java with OOo. And I don't know if this is where I should be posting this question but any information that anyone can give me would be very much appreciated. Let me start out with giving a thanks to Lars Behrmann for his link http://opendocument4all.com/content/view/70/1/ I used it to create my program using java. I have been fooling around with macros and learning more and more OOo Basic. But I am assuming that basic has it's limits. I would like to be able to take values from a spreadsheet and enter them to a website and then the user can enter another value and the result is emailed to me. I have already made the form in the webpage and a php file to email the results to me. I figure that using java I would be able to take the value out of the spreadsheet and insert it to the website (maybe I can't do it, it might not be possible). Now here is one of my problems it has been about 4 or 5 years since i took java programming in college. And when I did that all I used was some compiler program from microsoft. But maybe I am wrong but I could have sworn that the program created an executable file. The program that I wrote with the help of Lars Behrmann did not. Any pointers or help that you can give would be very much appreciated.
Back to top
View user's profile Send private message
Jiml
General User
General User


Joined: 10 Feb 2006
Posts: 24

PostPosted: Thu Mar 02, 2006 8:33 am    Post subject: java Reply with quote

I only know a little about Java programming, and nothing about using it to take values off of a spreadsheet, but I believe the executable that you want to create is a JAR file. See the java documentation as to how to create one with the jar tool, or you may be able to use eclipse to do it, but I am not at all familiar with that.
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Thu Mar 02, 2006 8:52 am    Post subject: Reply with quote

Yes I can make a jar file but isn't that file just similar to a zip file? Is it just a compression file??
Back to top
View user's profile Send private message
Jiml
General User
General User


Joined: 10 Feb 2006
Posts: 24

PostPosted: Thu Mar 02, 2006 9:29 am    Post subject: java Reply with quote

While a jar file is compressed, you can use it for more than that. see this extensive explanation from sun:

http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html

I think you would just need to have a runtime installed, and then you can execute the jar file by just clicking on it. I have one that I made some time ago and it still works.
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Thu Mar 02, 2006 11:43 am    Post subject: Reply with quote

Well I looked on this website http://mindprod.com/jgloss/jar.html#EXECUTING and I followed the instructions step by step. But I could not find where to change the step 4 about the "MIME" when I click on the jar file I get the error message "Failed to load Main Class manifest attribute". Anyone have any ideas???
Back to top
View user's profile Send private message
Jiml
General User
General User


Joined: 10 Feb 2006
Posts: 24

PostPosted: Thu Mar 02, 2006 4:01 pm    Post subject: Reply with quote

the proper mime type seems to be application/java-archive

fyi, Lots of stuff in my file types does not have a mime type.

I do not have jar in my file types, though, and I can still double click them to work them.
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Mon Mar 06, 2006 6:06 am    Post subject: Reply with quote

I do have a question now if I run the command java -jar "javaapplication1.jar" in the directory the jar file is in why would I get an error java.lang.noclassdeffoundererror:com/sun/star/comp/helper/Bootstrapexception

for this code:
Code:

package javaapplication1;

public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
    /**
     * code written by: Lars Behrmann
     * @param args the command line arguments
     */
    public static void main(String[] args) {
  //Call the bootstrap to get the Component context
       com.sun.star.uno.XComponentContext oComponentContext        = null;
       try
       {
           oComponentContext                   =
               com.sun.star.comp.helper.Bootstrap.bootstrap();
       }
       catch(com.sun.star.comp.helper.BootstrapException ex)
       {
           System.out.println(ex.getMessage());
       }
       
       if(oComponentContext != null)
       {
           try
           {
           //Get the service manager
           com.sun.star.lang.XMultiComponentFactory oMultiComponentFactory =
                       oComponentContext.getServiceManager();
           //Create a new desktop instance
                     Object oDesktop                           =
                       oMultiComponentFactory.createInstanceWithContext(
                        "com.sun.star.frame.Desktop", oComponentContext);
                    //Create a new component loader within our desktop
                   com.sun.star.frame.XComponentLoader oComponentLoader        =
                       (com.sun.star.frame.XComponentLoader)
                       com.sun.star.uno.UnoRuntime.queryInterface(
                       com.sun.star.frame.XComponentLoader.class,
                                         oDesktop);
                   //Create a blank writer document
                   com.sun.star.lang.XComponent oComponent             =
                       oComponentLoader.loadComponentFromURL(
                       "private:factory/swriter",  //Blank document
                       "_blank",                   //new frame
                       0,                      //no search flags
                       //No additional aruments
                       new com.sun.star.beans.PropertyValue[0]);
                   //Get the textdocument
                   com.sun.star.text.XTextDocument oTextDocument           =
                       (com.sun.star.text.XTextDocument)
                       com.sun.star.uno.UnoRuntime.queryInterface(
                       com.sun.star.text.XTextDocument.class, oComponent);
                   //Insert some text
                   oTextDocument.getText().setString("Hello I'm the text");
                   //Create a storable object
                   com.sun.star.frame.XStorable oStorable                  =
                       (com.sun.star.frame.XStorable)
                       com.sun.star.uno.UnoRuntime.queryInterface(
                           com.sun.star.frame.XStorable.class, oComponent);
                   //Store the document
                   oStorable.storeToURL(
                       "file:///C:/odtFiles/test2.odt",
                       //No additional aruments
                   new com.sun.star.beans.PropertyValue[0]);
           System.out.println("Document created and saved");
           }
           catch(Exception  ex)
           {
               System.out.println("An exception occurs "+ex.getMessage());
           }
       }
   }
   
}


but when I build and run the program using netbeans IDE 5.0 the code works.
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: Mon Mar 06, 2006 10:41 am    Post subject: Reply with quote

SomeoneHere wrote:
if I run the command java -jar "javaapplication1.jar" in the directory the jar file is in why would I get an error java.lang.noclassdeffoundererror:com/sun/star/comp/helper/Bootstrapexception

I would say that Java complains about the missing class com.sun.star.comp.helper.Bootstrapexception, which is located in the OOo jar file named "juh.jar". Is this "juh.jar" in your classpath? If not, add it there.

Take a look at your NetBeans classpath setting for you OOo project. There may be more OOo jar files (like jurt.jar, ridl.jar and unoil.jar) you need to get your code running.

With kind regards
hol.sten
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Mon Mar 06, 2006 11:06 am    Post subject: Reply with quote

hol.sten thank you very much for your idea but regretfully that wasn't it. I checked and the juh.jar, jurt.jar ,etc that you mentioned are all in my classpath both in netbeans and in the manifest file that the project created. That is one of the things that is weird to me that it works when I run in netbeans. But when I run it through the command line I get an exception. But please any more help or ideas that you or anyone have would be greatly appreciated.
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: Mon Mar 06, 2006 11:16 am    Post subject: Reply with quote

SomeoneHere wrote:
I checked and the juh.jar, jurt.jar ,etc that you mentioned are all in my classpath both in netbeans and in the manifest file that the project created.

Try to put the OOo jar files not in the manifest file but put them directly in the Java classpath. I'm not a jar guru either, so if I had your problem, I wouldn't put the OOo jar files inside my jar file. I would put them directly into the classpath. That is even the more flexible way if you want to use your jar file with different OOo versions.

With kind regards
hol.sten
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Mon Mar 06, 2006 11:43 am    Post subject: Reply with quote

hol.sten once again thanks for your suggestion but as far as I can tell everything is included in the classpath. All the classes from the OOo installation, and all Classes from the OOo SDK. I had read the instructions for netbeans when I first made the project and added them accordingly. I checking through everything again and they are in the classpath. But regretfully still the same error Crying or Very sad
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: Mon Mar 06, 2006 11:58 am    Post subject: Reply with quote

I want to return to this question:
SomeoneHere wrote:
if I run the command java -jar "javaapplication1.jar" in the directory the jar file is in why would I get an error

Let me guess: You use Windows XP? You start a command line through "Start" -> "Run" -> "Open: cmd"?
- If so: What does you CLASSPATH look like, if you enter the command "set" at the command line? Does it contain your OOo jar file? Let me see it, please.
- If not so: Describe what you do to execute java -jar "javaapplication1.jar"

With kind regards
hol.sten
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Mon Mar 06, 2006 12:06 pm    Post subject: Reply with quote

First off you are almost right I do use start->run->cmd but we use windows 2000 (regretfully our work software that we run can only be used on this platform)
This is what the set command brought up:

C:\Testing\JavaApplication1\dist>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\mark\Application Data
CI_HOLOS_CLI=C:\Program Files\Seagate Software\Open OLAP
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=SERVERX
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\mark
LOGONSERVER=\\SERVERX
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Os2LibPath=C:\WINNT\system32\os2\dll;
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\ENVELOP\PROGRAM
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 2 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0209
ProgramFiles=C:\Program Files
PROMPT=$P$G
SystemDrive=C:
SystemRoot=C:\WINNT
TEMP=C:\DOCUME~1\mark\LOCALS~1\Temp
TMP=C:\DOCUME~1\mark\LOCALS~1\Temp
USERDOMAIN=SERVERX
USERNAME=mark
USERPROFILE=C:\Documents and Settings\mark
windir=C:\WINNT
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: Mon Mar 06, 2006 12:22 pm    Post subject: Reply with quote

SomeoneHere wrote:
you are almost right I do use start->run->cmd

Good.

SomeoneHere wrote:
This is what the set command brought up:

C:\Testing\JavaApplication1\dist>set
...
CI_HOLOS_CLI=C:\Program Files\Seagate Software\Open OLAP
CommonProgramFiles=C:\Program Files\Common Files
...

Great. As I expected, although you told me the contrary: There is no CLASSPATH. Sorry that I write CLASSPATH uppercase, but it is mosly written that way, because it is an environment variable.

It does not suffice that you set your CLASSPATH inside NetBeans if you want to start a Java application from command line. Please set your CLASSPATH after you start your command line. And because this is a lot of writing, put your CLASSPATH and your Java command into a .bat file and retry executing your application through executing your newly written .bat file.

Your .bat file needs at least something like:
Code:
rem Helpful but not necessary
set JDK=C:\Program Files\Java\j2sdk1.4.2_06
set PATH=%JDK%\bin;%PATH%

rem Build Classpath
set CLASSPATH=.;insert here your OOo jar files separated with ;

rem Execute jar file
java -jar javaapplication1.jar


With kind regards
hol.sten
Back to top
View user's profile Send private message
SomeoneHere
OOo Enthusiast
OOo Enthusiast


Joined: 28 Oct 2005
Posts: 116
Location: Boston, Massachusetts USA

PostPosted: Mon Mar 06, 2006 12:33 pm    Post subject: Reply with quote

hol.sten sorry to bother you again with my foolish questions but the code you gave me to make the bat file. Do I need to put each individual jar file in there or can I just put the directory that all the jar files are in. Secondly the . that you have after the = sign is that needed before each file?
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
Goto page 1, 2  Next
Page 1 of 2

 
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