Page 1 of 3 123 LastLast
Results 1 to 20 of 45
  1. #1
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Unhappy Creating jarfile containing external jarfiles

    Hi there,
    I am trying to create a jar file that containing external jarfiles.I copied that external files into my location and create the manifest file Manifest.mf as below:

    Main-Class: MainClass
    Class-Path: jar1.jar jar2.jar ...

    and create the jar file using the command :

    jar cfm MyJar.jar Manifest.mf *

    I can execute this MyJar.jar at the location where I create that jar file..when am trying to execute it in another location its showing an exception regarding the external jar file such as java.lang.NoClassDefFoundError

    can anybody please help me........:(

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Before go further, move your newly create jar file into a different location. Then try to execute it, ok you say that you can't.

    Then extract the jar file on to the same location and try to execute the same jar file. What happened?

    I hope you use Netbeans for developing your java applications.

  3. #3
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    Thanks for your reply
    Yes. I moved that jar file in to another location and extract its content there. its executing.But I have a doubt ,is it the real way to execute a jar file?

    I create that jar file using the command jar cfm.......

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    No it's not the real way to execute a jar file. Seems that additional jar file make not refer the resources correctly.

    Did you have any addition resources in you project. I mean did you use addition folder for images or any. Those make not linked correctly.

    Quote Originally Posted by gowry
    I create that jar file using the command jar cfm.......
    Even that addition jar files?

  5. #5
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    No.The only additional things are the external jar files that I copied to my location for creating my jar file.




    Quote Originally Posted by Eranga View Post
    Even that addition jar files?
    That additional jar files are java3d libraries that are using in my project.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I never done this on notepad. Most of the IDEs gives the final jar files binding with all required libraries.

  7. #7
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    I tried to create jar file in Eclipse.but it gives the same exception as in the situation when am trying to excecute the created jar file in another location.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I don't know to say about Eclipse. I used Netbeans. There is a folder named 'dist' is created and that is the distribution package. There is a single jar file is included if you don't have use any libraries. If you use, there is a folder created inside the dist folder named lib.

    So all the time you have to use whole dist folder as your package. Rather using a single file. I've never try to make a single jar file, because in deploying I keep the same folder structure. :)

  9. #9
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    Thank you for the time spent here..
    But Still am in the middle of sea...

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by gowry View Post
    Thank you for the time spent here..
    Don't worry. It's pleasure to help to solve your question.

    Quote Originally Posted by gowry View Post
    But Still am in the middle of sea...

    You mean that, try on Netbeans and the result is same?

  11. #11
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    Yes.. I tried on NetBeans..As you wrote there is a dist folder and all the libraries are within that in the lib folder.. Jar file is executing in that location..
    But if i move that jar file into another location still there the same Exception..

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  13. #13
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    No. Its not working even after extracting the jar file.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by gowry View Post
    No. Its not working even after extracting the jar file.

    So you said inside the dist folder it works, and out of it it's not? Try it clean and build, then move the dist folder somewhere and try.

    Is that you application(code) is too large. If you are ok to send it here or PM to me, I can try. If you don't like to do it, I don't :mad::( I always ;)

  15. #15
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    Yes .Inside the dist folder its working.
    executing the moved jar file after clean and build reporting an exception :

    Failed to load Main-Class manifest attribute from
    JarFile.jar

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, after extracting the jar file you should have a folder name, META-INF, is that right. Check the file there, what is the content of it. Check there Main-class attribute, is that main class of your application?

  17. #17
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    There is no Main-Class attribute in the manifest file under the META-INF folder. that containing only the version and other such informations.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    That should be the error in this case. Because Main-class define the main class, or the starting point of the jar file.

    Here is an example of one of my project.

    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 10.0-b19 (Sun Microsystems Inc.)
    Main-Class: testproject.StartingPoint
    Class-Path: lib/beansbinding-1.2.1.jar lib/AbsoluteLayout.jar
    X-COMMENT: Main-Class will be added automatically by build
    See the last line, X-COMMENT, says that Main-class should be added automatically in the build.

  19. #19
    gowry's Avatar
    gowry is offline Member
    Join Date
    Apr 2008
    Location
    India
    Posts
    27
    Rep Power
    0

    Default

    Yes.In that case the abscense of main class in the manifest is the error.ok.. but with the previous manifest file before the clean and build and the manifest file I created myself ,having those attributes Class-Path and Main-Class. i think its a Class-Path issue of the external libraries that am using.. But I dont know how to solve it.

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 28
    Last Post: 10-26-2010, 04:39 AM
  2. External JavaScript files not loading
    By sajut in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 05:47 AM
  3. Using Runtime to execute external commands
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-05-2008, 09:14 AM
  4. External Program execution problems
    By vital101 in forum Advanced Java
    Replies: 3
    Last Post: 10-30-2007, 05:17 PM
  5. Use a external file in my program
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •