2 Replies Latest reply: Feb 20, 2010 5:39 AM by 843804 RSS

    Using external jars when creating runnable jar (when using JACOB)

    843804
      Hello all!

      My configuration - WinXPSP3 x86, jdk1.6.0_11, Eclipse 3.4.0

      I'm writing Java application using JACOB.
      I want make runnable jar from my application and use Eclipse's Export->Runnable jar utility.
      But Eclipse repacks libary jacob.jar to my jar - I don't want it and lisense doesn't allow it.
      What should I do with runnable jar, that I created with Eclipse to make it work with external jar - jacob.jar?
      In other words:

      I have almost canonical example of using JACOB:
      import javax.swing.JOptionPane;
      
      import com.jacob.activeX.ActiveXComponent;
      import com.jacob.com.Dispatch;
      import com.jacob.com.Variant;
      
      
      public class Main
      {
      public static void main(String[] args)
      {
      ActiveXComponent xl = new ActiveXComponent("Excel.Application");
      Object xlo = xl.getObject();
      try {
      System.out.println("version="+xl.getProperty("Version"));
      System.out.println("version="+Dispatch.get((Dispatch)xlo, "Version"));
      xl.setProperty("Visible", new Variant(true));
      Object workbooks = xl.getProperty("Workbooks").toDispatch();
      Object workbook = Dispatch.get((Dispatch)workbooks,"Add").toDispatch();
      Object sheet = Dispatch.get((Dispatch)workbook,"ActiveSheet").toDispatch();
      Object a1 = Dispatch.invoke((Dispatch)sheet, "Range", Dispatch.Get,
      new Object[] {"A1"},
      new int[1]).toDispatch();
      Object a2 = Dispatch.invoke((Dispatch)sheet, "Range", Dispatch.Get,
      new Object[] {"A2"},
      new int[1]).toDispatch();
      Dispatch.put((Dispatch)a1, "Value", "123.456");
      Dispatch.put((Dispatch)a2, "Formula", "=A1*2");
      //System.out.println("a1 from excel:"+Dispatch.get((Dispatch)a1, "Value"));
      JOptionPane.showMessageDialog(null, Dispatch.get((Dispatch)a1, "Value"));
      System.out.println("a2 from excel:"+Dispatch.get((Dispatch)a2, "Value"));
      Variant f = new Variant(false);
      Dispatch.call((Dispatch)workbook, "Close", f);
      } catch (Exception e) {
      e.printStackTrace();
      } finally {
      xl.invoke("Quit", new Variant[] {});
      }
      }
      }
      I made runnable jar. It contains: Main.class, folder META-INF with MANIFEST.MF and all JACOB (com.jacob...)
      If it includes all JACOB library it works perfect). When I delete all jacob from archive manually
      and change default manifest text:
      Manifest-Version: 1.0
      
      Class-Path: .
      
      Main-Class: Main
      
      
      
      Name: com.jacob
      
      Specification-Title: JACOB : Java COM Bridge
      
      Implementation-Title: JACOB : Java COM Bridge Java libraries
      
      Implementation-Version: 1.14.3 build 62 on 06-July-2008 13:28:52
      
      Specification-Vendor: http://jacob-project.sourceforge.net
      to something else, jar stops working. I have directory with my runnable jar "Jack.jar
      ", jacob.jar and jacob-1.14.3-x86.dll. I tried to add jacob.jar in Class-Path: "Class-Path: .,jacob.jar" - nothing happens after double click on my jar
      Can you tell me how can I solve this problem, probably there is some trick with blanc line at the end of manifest (but I don't change it), or there is another way to create runnable jar, or something else.
        • 1. Re: Using external jars when creating runnable jar (when using JACOB)
          800560
          MrAborigen wrote:
          I made runnable jar. It contains: Main.class, folder META-INF with MANIFEST.MF and all JACOB (com.jacob...)
          If it includes all JACOB library it works perfect). When I delete all jacob from archive manually
          and change default manifest text:
          Manifest-Version: 1.0
          
          Class-Path: .
          
          Main-Class: Main
          
          
          
          Name: com.jacob
          
          Specification-Title: JACOB : Java COM Bridge
          
          Implementation-Title: JACOB : Java COM Bridge Java libraries
          
          Implementation-Version: 1.14.3 build 62 on 06-July-2008 13:28:52
          
          Specification-Vendor: http://jacob-project.sourceforge.net
          to something else, jar stops working. I have directory with my runnable jar "Jack.jar
          ", jacob.jar and jacob-1.14.3-x86.dll. I tried to add jacob.jar in Class-Path: "Class-Path: .,jacob.jar" - nothing happens after double click on my jar
          Can you tell me how can I solve this problem, probably there is some trick with blanc line at the end of manifest (but I don't change it), or there is another way to create runnable jar, or something else.
          I don't know anything about Jacob but if jacob.jar is in the same directory as Jack.jar, then it should be
          Class-Path: jacob.jar

          The Class-Path entries are relative to the jar file and should be separated by a space character. You do not need to include a dot. "Class-Path: .,jacob.jar" is wrong.

          Edited by: atmguy on Feb 19, 2010 8:59 AM
          • 2. Re: Using external jars when creating runnable jar (when using JACOB)
            843804
            Thanks, atmguy!

            it works with "Class-Path: . ,jacob.jar"

            I tried many separators like ',' and ';' but I didn't try " ")