• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Extracted Jar file doesn't run while the application run from eclipse

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dears ,

I have a java application with many referenced libraries -(Apache POI some of them ) which I include in my build path.
All those libraries at my lib folder.
This code working correctly as expected from eclipse.

But it doesn't work when I have extracted jar file and try to run it from command line.

It throws below exception

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/use
rmodel/Sheet

This issue here that while I run the jar it doesn't see my libraries

Below my Jar where ReadExcelFileExample.class is the main class



I googled this issue and I tried the following and no one worked still give me the same exception :

1- Generate the MANIFEST while generating my jar to contains all the lib
2- java -cp ApplicationTest7.jar MyMainClass
3- java -cp "ApplicationTest7.jar;lib/*.jar" MyMainClass
4- java -cp "ApplicationTest7.jar;/lib/*;" MyMainClass


Am working on windows 7 and JDK / JRE 6

Please advice.
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the following things? These will be helpful to identify the root cause.
  • Command to create the JAR.
  • Manifest file contents.
  • Command to run the jar file.
  • classpath entries.
  •  
    Ramy Nady
    Ranch Hand
    Posts: 115
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tapas Chand wrote:Can you post the following things? These will be helpful to identify the root cause.

  • Command to create the JAR.
  • Manifest file contents.
  • Command to run the jar file.
  • classpath entries.


  • Hello ,

    1- I use eclipse export tool to get the jar file - the content at my last screen shot.
    2- Manifest file as below - Note that I removed currently Class-Path since it didn't work with me

    Manifest-Version: 7.0
    Created-By: Ramy Diab
    Main-Class: ReadExcelFileExample

    3- Many commands I tried - I mentioned all above.

    4- Class path contain reference to all my lib jars








     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you are creating JAR in Eclipse, then it has 3 options when you select Runable jar
    1. Extract required libs into JAR
    2. Package required libs into JAR
    3. Copy required libs into a sub-folder next to JAR

    So if you are selecting 2nd/3rd option there should not be any issue.
    In 2nd option POI JARs will be inside your generated JAR and accordingly entries will be done in MANIFEST.MF by eclipse.
    In 3rd option POI JARs will be put in a folder parallel to your generated JAR and accordingly classpath entries will be done in MANIFEST.MF by eclipse.

    Can you tell the steps you are following in Eclipse to create the JAR?
     
    Ramy Nady
    Ranch Hand
    Posts: 115
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Find the three steps below .

    1



    2-



    3-

    What ever default MANIFEST or creating my own MANIFEST



    4 Finish
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Please note that you are creating normal JAR...not runable JAR.
    All steps I mentioned in my previous post are for creating runable JAR because my first impression was you want to run the JAR file.

    If you create normal JAR in Eclipse, even if you mention Main-Class in MANIFEST.MF, eclipse will remove the entry while creating the JAR because Main-Class is not required for a normal JAR.

    So first make sure what is your requirement. Whether you want to create a JAR file and include that in other projects or you want to run the JAR file.

    If you want to run JAR file then you should select "runable jar" option instead of "jar" option in eclipse export.
     
    Ramy Nady
    Ranch Hand
    Posts: 115
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Chand a million for your help.

    1- I exported runnable jar file from eclipse , this option extract all the required lib into the generated jar.
    2- Run the generated jar as java -cp [my jar name] [main class]

    It worked as expected.

    Thanks again.
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It is recommended that you learn the concepts of JAR and try all options in command line before creating a JAR in Eclipse.
    Go through this

    On a separate note do not use JDK 6. Always use the current version.
    There are features in JDK 8 which are not available in JDK 6.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic