On Wed, 19 Jan 2005 20:40:32 +0100
Jochen Staerk <[EMAIL PROTECTED]> wrote:

> Hi,
> > I always thought that adding the class path to your manifest would
be 
> > sufficient and has the same effect than using the cp-commandline
switch 
> > but I could be completely mistaken.
> > 
> > I thought a MANIFEST like this would work:
> > 
> > ------------------8<------------------
> > Manifest-Version: 1.0
> > Main-Class: at/bestsolution/oeush/members/MembersAdmin
> > Class-Path: lib/a.jar
/usr/lib/openoffice/program/classes/officebean.jar
> > ...
> 
> 1) I'm not sure I'm right either, today was the first time I learned 
> about how to add classpaths to manifests but
> 2) AFAIK manifest-classpaths can be relative and CLASSPATHs are 
> absolute. And with a manifest very similar to yours (adding jurt and 
> juh.jar and stuff) I get a libofficebean.so not-found-exception.
> 
> bye,
> Jochen
> 

Hi Jochen,

normally if you have the oo-jars (all from oo-home/program/classes) in
your classpath (manifest or CLASSPATH or with the -cp switch) the
libraries are found. There is a helüper-class, which load the
native-libraries in the parent-directory of officebean.jar (if the
library is not in LD_LIBRARY_PATH or %PATH% on Windows).

If you want to deploy your application together with the oo-jars (in a
relative subdirectory) the native-libraries cannot be found.

If I understand you correct and you want to deploy your application
(some mails above on this list) on different systems and OS. You have to
find a way to set the correct-classpath and native-ölibrary-path on the
target system. 

You can use start-scripts (run.bat run.sh) which create a classpath and
launch your application with java -cüüp mypath my.package.Main. 
But the users have to set the OO-path by hand before. In this case you
cannot use a selfstarting jar.


You can use a classloader to load your application. There you can use
a selfstarting jar (double-click on Windows). There are some
launcher-projects available like:
http://jakarta.apache.org/commons/launcher/

You can develop your own Launcher and add the oo-jars from
the target-system to your application. 

Example:

create a subdirectory 'lib' of your application and add there all your
application-jars.

In the parent-directory place the launcher-class or self-starting jar
like(untested):

import java.io.*;
import java.net.*;
import java.util.*;

public class Launcher{

  public Launcher(){


  }

  
  public static void main(String[] args){
     
    Launcher l = new Launcher();
    l.launchApplication(args);
    

  }


  public launchApplication(String[] args){
    ArrayList urls = new ArrayList();
   
    //add your application jars 
    addJars(urls,"lib");  
  
   //get now the path of the OO-installation
   //from a property-file, dialog or scan the filesystem

   String oopath = get...();

   //add all to the classpath
   addJars(urls,oopath); 

   //create URL[] from the urls-List
   URL[] classpath ...

   URLClassLoader loader = new URLClassLoader(classpath);
   
   //now load your application Main-class and start this
   
  try{
     Class clazz = loader.loadClass("my.Main");
 
  
   
    //get the main-method
    Class[] params = new Class[1];
    params[0] = args.getClass();
    Method m = clazz.getDeclaredMethod("main",params);
    
    //prepare the args
    Object[] methodparams = new Object[1];
    //the args from the commandline
    methodparams[0] = args; 
   
    //lauch the application
    m.invoke(null,methodparams);
   


  }catch(Exception e){
   //handle this

  }


  }

 
  private void addJars(List list,String dir){
      File f = new File(dir);
      if(f.isDirectory()){
        File[] jars = f.listFiles();
        for(int i=0;i<jars.length;i++){
         if(jars[i].getName().toLowerCase().endsWith(".jar")){
            
             try{

               list.add(jars[i].toURI().toURL();
            
              }catch(Excpetion e){
                 
                //handle this
           
              }
 
         }

        }


     }

  }
}


This will launch your application with custom-classloader, which puts
the oo-jars to his classpath. 

On the windows-platform you will get problems if the oo-home/program
directory is not int the %PATH%. You can preload the native-libs, but
you need the right order of the libs and this can simple changed by
newer OO-releases. 

I hope this can help.

Best Regards,

Simon

















---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to