Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: How to create jar file from eclipse?

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to create jar file from eclipse?

    Hi,
    I need to create a JAR file of my java project. In my project I have added 3 additional jar files - jython-2.5.4-rc1.jar,netty-3.9.0.Final.jar and commons-codec-1.9.jar. I have created JAR file of my project from Eclipse. But when I try to run that jar file from command promt (java -jar myjar.jar) I get NoClassFoundException for one of my additional jar files. Any idea why I am getting this error.

    exception.jpg


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to create jar file from eclipse?

    What is in the jar that you create? Is that class in there? Are any classes from the library jars in there?

    Eclipse has options to include library jars inside a runnable jar. Make sure you select them, otherwise you'll have to add the library jars to the classpath whenever you run it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to create jar file from eclipse?

    options to include library jars inside a runnable jar.
    Does that mean there is a classloader that can read classes from a jar file that is inside of another jar file?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create jar file from eclipse?

    In my project there are two java classes which use other classes from external jars. This is how I have created my jar file in eclipse-
    jar1.jpg
    jar2.jpg
    jar3.jpg

    Everything seems fine but I am getting that error message when I run it from command promt.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to create jar file from eclipse?

    Where is the missing class file? Do you want all the classes merged into a single jar file or can some classes be kept in other jar files that are referenced by an entry in the Manifest file?

    NOTE: You can ignore most of this. I don't know how to use eclipse.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to create jar file from eclipse?

    Quote Originally Posted by Norm View Post
    Does that mean there is a classloader that can read classes from a jar file that is inside of another jar file?
    Sorta. You can either extract the .class files from the library jars into the runnable jar, or add the library jar files themselves along with classes that allow loading from them, all inside the runnable jar. More info here: eclipse - What is the difference between runnable jar library handling options? - Stack Overflow

    --- Update ---

    OP, you want to be exporting a *runnable* jar file.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Norm (May 14th, 2014)

  8. #7
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create jar file from eclipse?

    My two java files and three external jars are there. So what did you mean by the missing class file?

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to create jar file from eclipse?

    Quote Originally Posted by shoharb.uddin View Post
    My two java files and three external jars are there. So what did you mean by the missing class file?
    We're simply referring to the error.

    Just adding the jars isn't enough. You need to add the classes that handle loading from the library jars. Eclipse does this automatically when you export as a RUNNABLE jar. That's a different option in the export menu.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. The Following User Says Thank You to KevinWorkman For This Useful Post:

    shoharb.uddin (May 14th, 2014)

  11. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How to create jar file from eclipse?

    I get NoClassFoundException
    I was calling the class that was not found the missing class.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #10
    Junior Member
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to create jar file from eclipse?

    ok. so far i have tried only jar not runnable jar. let me try it now and then get back to you.

    --- Update ---

    It works after creating the runnable jar file instead of creating the simple jar file.
    Thank You very much.

  13. #11

    Default Re: How to create jar file from eclipse?

    Creating a JAR file using Eclipse IDE:

    Right click on your project, which you want to create a JAR file of. And select Export from the context menu.

    Select JAR file from Java folder and click Next.

    In eclipse Latest version Runnable JAR file is added.

    Provide the Destination path and click on Finish to create the JAR.

Similar Threads

  1. I can not create an Executable .Jar File
    By sakonpure6 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 27th, 2013, 08:55 PM
  2. Cannot create executable jar file
    By viper_pranish in forum Java Theory & Questions
    Replies: 4
    Last Post: March 20th, 2013, 10:31 AM
  3. How do I create and run a jar file?
    By Ecen in forum Java Theory & Questions
    Replies: 10
    Last Post: August 4th, 2012, 11:50 PM
  4. Replies: 10
    Last Post: January 12th, 2011, 05:48 AM
  5. Replies: 5
    Last Post: November 13th, 2010, 01:53 PM