Results 1 to 11 of 11
  1. #1
    themulator is offline Member
    Join Date
    Oct 2010
    Posts
    15
    Rep Power
    0

    Exclamation How can I pack all files into a single jar file?

    Hello all!

    I've recently finished making a game and was wondering if it is possible to pack all media files like pictures and audio into a single jar file similar to Java ME. If it is possible how can I do it? I am currently using Eclipse, however, when I export the game as a jar, the media files have to be outside the jar file. Any help will be appreciated. Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by themulator View Post
    ...I am currently using Eclipse, however, when I export the game as a jar, the media files have to be outside the jar file.
    Why do you assume this? It is certainly not true.

  3. #3
    themulator is offline Member
    Join Date
    Oct 2010
    Posts
    15
    Rep Power
    0

    Default

    Well, I've got it to pack into the jar file, but now when I try to directly run the jar file, it gives me this "failed to load main class manifest..." message

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Then you've some error in creating the Jar file. Are you specifying a main class, the one with the main method that starts your app in the manifest file?

  5. #5
    themulator is offline Member
    Join Date
    Oct 2010
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Then you've some error in creating the Jar file. Are you specifying a main class, the one with the main method that starts your app in the manifest file?
    yes, Ive done that, however now some of the images in the game don't appear.
    Is there a special way to modify the manifest file?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    How are you handling the images? Are you trying to find them as files or as resources? Are you getting any exceptions when loading the images? Are you catching and handling exceptions when you do this?

  7. #7
    themulator is offline Member
    Join Date
    Oct 2010
    Posts
    15
    Rep Power
    0

    Default

    I'm handling images and audio as files. In eclipse, if you put files into the project folder, you automatically have direct access to them, but after packaging and exporting as a jar file, I can visually see the files in the jar file, but none of them are loaded :(

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by themulator View Post
    I'm handling images and audio as files.
    Then this is a significant error since files don't exist within jars, and you will have to change what you are doing and refer to your resources as resources. Please read the Jar tutorials for more on how to do this.


    In eclipse, if you put files into the project folder, you automatically have direct access to them, but after packaging and exporting as a jar file, I can visually see the files in the jar file, but none of them are loaded :(
    This has nothing to do with Eclipse and all to do with mishandling resources. The tutorials will show you how to fix this.

  9. #9
    themulator is offline Member
    Join Date
    Oct 2010
    Posts
    15
    Rep Power
    0

    Default

    which tutorials are you exactly referring to?

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

  11. #11
    Armadillo is offline Member
    Join Date
    Jul 2010
    Posts
    15
    Rep Power
    0

    Default

    You should do something like:
    class.getClassLoader().getResourceAsStream(....)
    Stackoverflow has a lot of q&A about this, for example:
    open resource with relative path in java - Stack Overflow

    But its a pain, resource loading. I stumbled on this post because i have problems finding my resources inside one-jar jar.

    good luck

Similar Threads

  1. multiple java files with single connection code
    By hitesh in forum Advanced Java
    Replies: 7
    Last Post: 11-23-2010, 08:18 AM
  2. pack libraries into jar file
    By BigBear in forum New To Java
    Replies: 1
    Last Post: 05-24-2010, 11:19 AM
  3. Packaging all files into a single executable .jar
    By ichwar in forum New To Java
    Replies: 5
    Last Post: 01-27-2010, 01:31 AM
  4. Merged TIF file size is more larger than the sum of single TIF files
    By subrahmanyam.adapa in forum Advanced Java
    Replies: 3
    Last Post: 01-26-2009, 01:19 PM
  5. Replies: 1
    Last Post: 06-06-2007, 04:20 AM

Tags for this Thread

Posting Permissions

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