Creating Archive Files in Eclipse with images.

Discussion in 'Java' started by Sanny, May 18, 2011.

  1. Sanny

    Sanny Guest

    I have created an applet that has 20-30 images.

    I want all of them to be put in one archive file. and I just display
    the archive file in applet.

    <applet code="HelloWorld.class" width="800" height="600"
    archive="Helloworld.jar">

    I found somewhere I can omit the .class prefix.

    <applet code="HelloWorld" width="800" height="600"
    archive="Helloworld.jar">

    My images are on the same directory as the classfile.

    How to create a .jar file in eclipse?

    I tried to Export in Eclipse It gives two options.

    1. Export -> Create Archive file.
    2. Export -> Java -> Create Jar

    Do they both are the same things?

    Can I create .zip instead of .jar will that work with applets?

    <applet code="HelloWorld" width="800" height="600"
    archive="Helloworld.jip">

    I found Eclipse gives no option to add images to the .jar file. Can I
    use winzip to create a zip/ jar file?

    How to include all images in the .jar file.

    Incase I use .zip and compression will it work on all browsers.

    I find it asks for Manifest File? What is this? What information can I
    give to Manifest file? What will happen If I do not give manifest
    file. As my applet already know the class to start with?

    Once I create the .jar file Do I have to add the .class files to the
    server? Will .jar provide everything the applet needs?

    Bye
    Sanny
    Sanny, May 18, 2011
    #1
    1. Advertising

  2. Sanny

    markspace Guest

    On 5/18/2011 5:16 AM, Sanny wrote:

    > My images are on the same directory as the classfile.


    Normally, you put extra files (like images) in the source (src)
    directory, not the class file directory.

    Those extra files will be added to your .jar file when the .jar is built.

    >
    > How to create a .jar file in eclipse?


    You can also do this manually, add or remove files yourself as you please.

    <http://download.oracle.com/javase/tutorial/deployment/jar/>


    > Can I create .zip instead of .jar will that work with applets?


    If you're asking what I think you are, the answer is no. You can read a
    ..zip file from an applet, but I don't think you want to do that.

    <http://download.oracle.com/javase/6/docs/api/java/util/zip/ZipInputStream.html>


    > I found Eclipse gives no option to add images to the .jar file. Can I
    > use winzip to create a zip/ jar file?


    Use the jar utility, that I linked to above.
    markspace, May 18, 2011
    #2
    1. Advertising

  3. Sanny

    Sanny Guest

    Thanks for the help.

    I created a jar file with all classes. But still the applet is not5
    working.

    <applet code="HelloWorld.class" width="800" height="600"
    archive="FightGame.jar">

    FightGame.jar has a class: HelloWorld.class that runs the applet.

    Here FightGame.jar is having all the files the HelloWorld.class applet
    needs.

    I put the html page and FightGame.jar on same folder but the applet is
    not loading.

    However when I put HelloWorld.class directly in that folder this
    applet runs perfectly.

    So the Browser is not loading FightGame.jar even though I have added
    it in the <applet> tag.

    Why are the classes HelloWorld.class inside FightGame.jar not working?

    Incase I do not use FightGame.jar and directly put the
    HelloWorld.class in the same folder the applet runs without any
    problem.

    Bye
    Sanny
    Sanny, May 19, 2011
    #3
  4. Sanny

    markspace Guest

    On 5/19/2011 10:20 AM, Sanny wrote:

    > However when I put HelloWorld.class directly in that folder this
    > applet runs perfectly.
    >
    > So the Browser is not loading FightGame.jar even though I have added
    > it in the<applet> tag.



    I don't know about this one. Check your paths again to make sure they
    are all correct. You might have to use a sniffer like Wireshark to
    verify that the Java plug-in is looking where you think it is looking.
    markspace, May 19, 2011
    #4
  5. Sanny

    Jeff Higgins Guest

    On 05/19/2011 01:20 PM, Sanny wrote:
    > Thanks for the help.
    >
    > I created a jar file with all classes. But still the applet is not5
    > working.
    >


    Would the Java Console be of any use in debugging this problem?
    Jeff Higgins, May 19, 2011
    #5
  6. Sanny

    markspace Guest

    On 5/19/2011 10:20 AM, Sanny wrote:
    > Why are the classes HelloWorld.class inside FightGame.jar not working?


    I found this, it might help you with some definitive answers:

    <http://download.oracle.com/javase/6/docs/technotes/guides/plugin/developer_guide/contents.html>
    markspace, May 19, 2011
    #6
  7. Sanny

    Sanny Guest

    > I don't know about this one.  Check your paths again to make sure they
    > are all correct.  You might have to use a sniffer like Wireshark to
    > verify that the Java plug-in is looking where you think it is looking.


    When creating a Jar file I get below errors. I am able to play the
    applet as an Application with Eclipse as it has got main() function.
    But When I click the FightGame.jar It closes immidietly.

    JAR creation failed. See details for additional information.
    Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    entry: META-INF/MANIFEST.MF
    Resource /FightGame does not exist.
    Resource /FightGame does not exist
    Resource /FightGame does not exist.
    Problem writing /FightGame/.classpath to JAR: duplicate
    entry: .classpath
    Problem writing /FightGame/.project to JAR: duplicate
    entry: .project
    Problem writing /FightGame/HelloWorld.java to JAR: duplicate entry:
    HelloWorld.java
    Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    entry: META-INF/MANIFEST.MF
    Problem writing /FightGame/fightgame.jardesc to JAR: duplicate
    entry: fightgame.jardesc
    Resource /FightGame does not exist.
    Resource /FightGame does not exist.
    Resource /FightGame does not exist.

    Despite the errors the FightGame.jar is created.

    I have kept all my images in "src" folder. I find the jar do not add
    the content of "src" folder.

    How to ask the Eclipse to add all files from "src" folder into the
    jar.

    It gives me no option to include a folder "src"

    When I double click the Jar a window opens for a few sec and closes
    without showing any error.

    Bye
    Sanny
    Sanny, May 20, 2011
    #7
  8. Sanny

    Lew Guest

    On 05/20/2011 05:20 AM, Sanny wrote:
    >> I don't know about this one. Check your paths again to make sure they
    >> are all correct. You might have to use a sniffer like Wireshark to
    >> verify that the Java plug-in is looking where you think it is looking.

    >
    > When creating a Jar file I get below errors. I am able to play the
    > applet as an Application with Eclipse as it has got main() function.
    > But When I click the FightGame.jar It closes immidietly.
    >
    > JAR creation failed. See details for additional information.
    > Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    > entry: META-INF/MANIFEST.MF
    > Resource /FightGame does not exist.
    > Resource /FightGame does not exist
    > Resource /FightGame does not exist.
    > Problem writing /FightGame/.classpath to JAR: duplicate
    > entry: .classpath


    Don't include .classpath in the JAR. It's a development artifact and has no
    place in the deployment.

    > Problem writing /FightGame/.project to JAR: duplicate
    > entry: .project


    Don't include .project in the JAR. It's a development artifact and has no
    place in the deployment.

    > Problem writing /FightGame/HelloWorld.java to JAR: duplicate entry:
    > HelloWorld.java
    > Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    > entry: META-INF/MANIFEST.MF
    > Problem writing /FightGame/fightgame.jardesc to JAR: duplicate
    > entry: fightgame.jardesc


    Don't include fightgame.jardesc in the JAR. It's a development artifact and
    has no place in the deployment.

    > Resource /FightGame does not exist.
    > Resource /FightGame does not exist.
    > Resource /FightGame does not exist.
    >
    > Despite the errors the FightGame.jar is created.
    >
    > I have kept all my images in "src" folder. I find the jar do not add
    > the content of "src" folder.


    You usually don't include source in the deployment artifacts.

    > How to ask the Eclipse to add all files from "src" folder into the
    > jar [sic].


    Why?

    > It gives me no option to include a folder "src"


    That's because it isn't part of the deployment. Instead, it copies resources
    FROM "src" to the build directory.

    > When I double click the Jar [sic] a window opens for a few sec and closes
    > without showing any error.


    That's what the program does, apparently.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 20, 2011
    #8
  9. Sanny

    Sanny Guest

    > >    Problem writing /FightGame/fightgame.jardesc to JAR: duplicate
    > > entry: fightgame.jardesc

    >
    > Don't include fightgame.jardesc in the JAR.  It's a development artifact and
    > has no place in the deployment.


    I removed all unwanted files.

    Still I am getting below errors.

    JAR creation failed. See details for additional information.
    Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    entry: META-INF/MANIFEST.MF
    Problem writing /FightGame/HelloWorld.java to JAR: duplicate entry:
    HelloWorld.java
    Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    entry: META-INF/MANIFEST.MF
    Resource /FightGame does not exist.
    Resource /FightGame does not exist.
    Resource /FightGame does not exist.

    > > I have kept all my images in "src" folder. I find the jar do not add
    > > the content of "src" folder.

    >
    > You usually don't include source in the deployment artifacts.


    "markspace" suggested me to create a src folder and put all images
    into that folder.

    I wanted some way to include all images and docs needed by the applet
    into a single .jar file.


    > > How to ask the Eclipse to add all files from "src" folder into the
    > > jar [sic].

    >
    > Why?


    So, that I get one .jar file instead of 20-30 images which takes
    longer to download.


    > > It gives me no option to include a folder "src"

    >
    > That's because it isn't part of the deployment.  Instead, it copies resources
    > FROM "src" to the build directory.


    Should I put the images into "lib" folder? Or I create a build folder.
    How can I suggest Eclipse to put all images into the .jar file?


    > > When I double click the Jar [sic] a window opens for a few sec and closes
    > > without showing any error.

    >
    > That's what the program does, apparently.


    No, This is a 2d fighting game When I use Run in eclipse it starts the
    2d game. But when I click the .jar files the window opens for a few
    sec but then closes automatically. Without showing any error.

    Bye
    Sanny
    Sanny, May 20, 2011
    #9
  10. Sanny

    Lew Guest

    ATTRIBUTE YOUR CITATIONS!

    You've been around this newsgroup too long not to know better, Sanny.

    Sanny wrote:
    >>> Problem writing /FightGame/fightgame.jardesc to JAR: duplicate
    >>> entry: fightgame.jardesc


    Lew wrote:
    >> Don't include fightgame.jardesc in the JAR. It's a development artifact and
    >> has no place in the deployment.


    Sanny [etc. - work it out]:
    > I removed all unwanted files.


    No, you didn't. Apparently you are trying to include some unwanted files more
    than once.

    > Still I am getting below errors.
    >
    > JAR creation failed. See details for additional information.
    > Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    > entry: META-INF/MANIFEST.MF
    > Problem writing /FightGame/HelloWorld.java to JAR: duplicate entry:
    > HelloWorld.java


    One does not normally include source in a JAR, or at least not in the
    deployment JAR. Why do you wish to do so?

    > Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    > entry: META-INF/MANIFEST.MF
    > Resource /FightGame does not exist.
    > Resource /FightGame does not exist.
    > Resource /FightGame does not exist.


    What is "Resource /FightGame"?

    What did you set for it to try to include that?

    Three times?

    What else have you set to cause multiple attempts to write to the JAR?

    Why are you including source?

    >>> I have kept all my images in "src" folder. I find the jar do not add
    >>> the content of "src" folder.


    >> You usually don't include source in the deployment artifacts.


    > "markspace" suggested me to create a src folder and put all images
    > into that folder.


    And nowhere did he tell you to include that folder in the JAR. You made that
    part up. Don't blame him for your behavior.

    > I wanted some way to include all images and docs needed by the applet
    > into a single .jar file.


    It's not by including the "src" directory, it's by copying resources into the
    build directory, which Eclipse does automatically. When resrources are in the
    designated source folders, Eclipse builds them into the JAR.

    >>> How to ask the Eclipse to add all files from "src" folder into the
    >>> jar [sic].


    Questions should be phrased as interrogatives.

    AFAIK it's enough to put the resource in the "src" folder tree, and Eclipse
    copies it. I would have to check the Eclipse documentation for the details.

    >> Why?

    >
    > So, that I get one .jar file instead of 20-30 images which takes
    > longer to download.


    That doesn't answer my question. I asked why you wish to include the "src"
    directoy and you answered why you included specific image files. Including
    the files makes perfect sense.

    >>> It gives me no option to include a folder "src"


    >> That's because it isn't part of the deployment. Instead, it copies resources
    >> FROM "src" to the build directory.


    > Should I put the images into "lib" folder? Or I create a build folder.


    No. The Eclipse documentation explains how to set up a project.

    > How can I suggest Eclipse to put all images into the .jar file?


    RTFM.
    <http://help.eclipse.org/helios/index.jsp>
    <http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/ref-export-jar.htm>
    <http://help.eclipse.org/helios/index.jsp>
    <http://help.eclipse.org/helios/topic/org.eclipse.jdt.doc.user/reference/ref-properties-build-path.htm?resultof=%22%62%75%69%6c%64%22%20%22%61%70%70%6c%69%63%61%74%69%6f%6e%22%20%22%61%70%70%6c%69%63%22%20%22%4a%41%52%22%20%22%6a%61%72%22%20>

    and more, found within a few minutes of a search through the Eclipse
    documentation online.

    >>> When I double click the Jar [sic] a window opens for a few sec and closes
    >>> without showing any error.


    >> That's what the program does, apparently.


    > No, This is a 2d fighting game When I use Run in eclipse it starts the
    > 2d game. But when I click the .jar files the window opens for a few
    > sec but then closes automatically. Without showing any error.


    How do you know what it does? You think the same program is called by the
    double-click as by Eclipse's action, but what is your evidence?

    You draw a conclusion without looking at all the facts.

    Appearing then disappearing when you double-click the JAR is either a failure
    to associate the .jar extension with "java -jar" or a problem internal to the JAR.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 20, 2011
    #10
  11. Sanny

    Sanny Guest

    > > I removed all unwanted files.
    >
    > No, you didn't.  Apparently you are trying to include some unwanted files more
    > than once.


    I am using Export-> Java -> JAR File

    Then I get a Window:

    On One Side: FightGame
    This is my package name

    On Other Side

    [.] .ClassPath
    [.] .project

    I uncheck above two files as you suggested.

    When I Click [.] FightGame

    I get a few more classes under it
    1. (default package)
    2. library classes
    3. Meta-Inf

    I removed the Meta-Inf files this time.

    When I click (default package)On right window I get

    [.] HelloWorld.java

    I tried removing HelloWorld.java

    But then It do not allow me to choose the Main Class: HelloWorld.
    And It do not allow me to create a Jar when I disable: HelloWorld.java

    Now when I Create Jar

    I get below errors.

    JAR export finished with warnings. See details for additional
    information.
    Problem writing /FightGame/HelloWorld.java to JAR: duplicate entry:
    HelloWorld.java
    Problem writing /FightGame/META-INF/MANIFEST.MF to JAR: duplicate
    entry: META-INF/MANIFEST.MF


    > One does not normally include source in a JAR, or at least not in the
    > deployment JAR.  Why do you wish to do so?


    I dont want to put HelloWorld.java But It do not allow me to choose
    "Main Class" when I disable HelloWorld.java from the list.

    > > I wanted some way to include all images and docs needed by the applet
    > > into a single .jar file.

    >
    > It's not by including the "src" directory, it's by copying resources intothe
    > build directory, which Eclipse does automatically.  When resrources arein the
    > designated source folders, Eclipse builds them into the JAR.


    What is the Build directory? In my workspace I cant find any "Build"
    folder, Do I need to create it?

    > Questions should be phrased as interrogatives.
    >
    > AFAIK it's enough to put the resource in the "src" folder tree, and Eclipse
    > copies it.  I would have to check the Eclipse documentation for the details.


    I added to "src" folder too But It is not Copying to the .jar.

    Bye
    Sanny
    Sanny, May 20, 2011
    #11
  12. Sanny

    Lew Guest

    ATTRIBUTE YOUR CITATIONS, SANNY!
    ATTRIBUTE YOUR CITATIONS, SANNY!
    ATTRIBUTE YOUR CITATIONS, SANNY!
    ATTRIBUTE YOUR CITATIONS, SANNY!
    ATTRIBUTE YOUR CITATIONS, SANNY!
    ATTRIBUTE YOUR CITATIONS, SANNY!

    Jesus H. Tapdancing CHRIST, Sanny!

    Sanny wrote:

    No, you did not. Lew wrote:
    >> One does not normally include source in a JAR, or at least not in the
    >> deployment JAR. Why do you wish to do so?


    THIS is what Sanny wrote:
    > I dont want to put HelloWorld.java But It do not allow me to choose
    > "Main Class" when I disable HelloWorld.java from the list.


    You want HelloWorld.class in the JAR, not the source.

    and THIS is what Sanny wrote:
    >>> I wanted some way to include all images and docs needed by the applet
    >>> into a single .jar file.


    and THIS Lew wrote:
    >> It's not by including the "src" directory, it's by copying resources into the
    >> build directory, which Eclipse does automatically. When resources are in the
    >> designated source folders, Eclipse builds them into the JAR.


    Sanny [etc.]:
    > What is the Build directory? In my workspace I cant find any "Build"
    > folder, Do I need to create it?


    It is part of the project, not the workspace, and you set it up when you set
    up the project. I believe the default is "bin/" relative to your project, but
    you get to rename it.

    Have you read the instructions for Eclipse? It doesn't sound like you have.

    Start with:
    <http://help.eclipse.org/helios/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-3.htm>

    Note "Create separate folders for sources and class files" and "Configure
    default..."

    <http://help.eclipse.org/helios/topic/org.eclipse.jdt.doc.user/tasks/tasks-32.htm>

    RTFM.

    >> Questions should be phrased as interrogatives.
    >>
    >> AFAIK it's enough to put the resource in the "src" folder tree, and Eclipse
    >> copies it. I would have to check the Eclipse documentation for the details.


    > I added to "src" folder too But It is not Copying to the .jar.


    And the Eclipse documentation says what about this? Did you read the links I
    posted before? Did you?

    Why did you clip all those links from your response? Did you read them?

    These links will help you not at all if you don't read them. You have to read
    them. Read them and study them. Learn from them when you read them. It's
    the reading of them that will help you. You should probably read them. Who
    knows, reading the documentation might answer your questions!

    RTFM.

    Please note that you could just as easily searched the help files as have me
    do it for you. I found all this information in the few minutes since reading
    your posts, in order to help you. You couldn't do that?

    RTFM.

    --
    Lew
    RTFM.
    Lew, May 20, 2011
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Stien
    Replies:
    4
    Views:
    2,230
    n@th@n
    Feb 9, 2005
  2. John Goche
    Replies:
    2
    Views:
    11,155
    Darryl L. Pierce
    Jan 22, 2006
  3. Pierre
    Replies:
    2
    Views:
    469
    Roedy Green
    Feb 25, 2006
  4. Replies:
    1
    Views:
    720
    Alan Krueger
    Sep 11, 2006
  5. RC Gray
    Replies:
    3
    Views:
    357
    RC Gray
    Dec 28, 2011
Loading...

Share This Page