Results 1 to 19 of 19
  1. #1
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Trying to make runnable jars

    I am trying to make a runnable .jar using the cmd line here's what is happening
    in my jar folder on my c:\ drive


    Trying to make runnable jars-ss1.png



    my game package contents:


    Trying to make runnable jars-ss2.png

    Here is my manifest file:


    Trying to make runnable jars-ss3.png


    I created the jar file fine but I get an error when I try to run it.
    This pic will show me creating and the error when trying to run:


    Trying to make runnable jars-cmd.png

    Thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Trying to make runnable jars

    Does Frame.java start with a package statement?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    yes
    Java Code:
    package game;

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Trying to make runnable jars

    So, the class isn't Frame, it's game.Frame. And not game.Frame.class either.

    With your present manifest, Java is looking for a class named class (which you couldn't actually create, since class is a reserved keyword) in the package Frame.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    thanks it worked! The reason I did the Frame.class is because the example in the java tutorials showed it as mainclass.class but any way i get it now....One other question I have two folders in my eclipse project under the src folder: images and sounds. In the tutorials I didn't see anything on how to include these. The path to the images are coded as:
    Java Code:
    "src/images/picture.png" 
    
    "src/sounds/soundEffect.wav"
    so how do I include these resources in my project and do i need to change the path to do so?


    Thanks!

  6. #6
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    I meant include in my jar not my project

  7. #7
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    ok..I figured out how to include the resources and the program works........but it only works from command line using

    java -jar space.jar

    if I double click on the jar file I get and error:
    cannot find main class game.Frame

    how can I make it so it works when clicked?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Trying to make runnable jars

    If it works when you manually enter the java -jar space.jar command, then it should work when you double click on the jar file to open it. Is there an old version of the jar file that is confusing this?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    no...I even renamed it and its says it cannot find the main class and it only runs from the directory it was crated in on the cmd line

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Trying to make runnable jars

    Move the jar file to a testing location directory, open a command prompt window and enter: java -jar <THEJARFILENAME>.jar
    You must be missing some files in the jar file if it only works in one directory.

    Copy the console and paste here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    I put it in a folder on the c: drive name jarTest



    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Remo>java -jar space.jar
    Error: Unable to access jarfile space.jar

    C:\Users\Remo>

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Trying to make runnable jars

    You must change the directory (use the cd command) to be in the folder with the jar file. The java command did NOT find the jar file in the Remo folder.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    The program ran but no Images or sound files.

    Here's what I get when the jar is clicked:

    Trying to make runnable jars-screen.png



    cmd line contents

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Remo>java -jar space.jar
    Error: Unable to access jarfile space.jar

    C:\Users\Remo>cd\

    C:\>cd jartest

    C:\jarTest>java -jar space.jar
    java.io.FileNotFoundException: src\game.txt (The system cannot find the path spe
    cified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.jav a:138)
    at java.io.FileInputStream.<init>(FileInputStream.jav a:97)
    at java.io.FileReader.<init>(FileReader.java:58)
    at game.Frame.<init>(Frame.java:76)
    at game.Frame.main(Frame.java:170)
    Wave file not found: src/sounds/Intro.wav

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Trying to make runnable jars

    java.io.FileNotFoundException: src\game.txt
    Is that file for input only? It is not updated, just read?
    You need to add that file to the jar file and to change the code so that it gets the file using getResource()

    And do the same for ALL files the program uses. Put them in the jar file and change the code.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    is getresource() a swing method and how do I "put them in the jar file"?

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Trying to make runnable jars

    Do a Search on the forum for getResource for many code samples on using that method.

    Use the jar command to put files in a jar file.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Trying to make runnable jars

    here is some of my Images in code:
    Java Code:
    ImageIcon ic = new ImageIcon("src/images/space_background.png");
    		ImageIcon icChicago = new ImageIcon("src/images/chicago.png");
    		ImageIcon icGo = new ImageIcon("src/images/SpaceCraftGo.png");
    		ImageIcon icPlode = new ImageIcon("src/images/explode.png");
    		
    		//actually load background image into image object
    		background = ic.getImage();
    		chicago = icChicago.getImage();
    		blast = icGo.getImage();
    would I do this?

    Java Code:
    URL myUrl = background.getClass().getResource("src/images/space_background.png");
    or this
    Java Code:
    URL myUrl = ic.getClass().getResource("src/images/space_background.png");
    if that is correct what else do I have to do to have the image end up in my jar?

  18. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Trying to make runnable jars

    Read the API for ImageIcon. What are the available constructors? Do you see one that fits your requirement?

    Have you read through the Oracle tutorial on How to Use Icons?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  19. #19
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Trying to make runnable jars

    Quote Originally Posted by mwr1976 View Post
    what else do I have to do to have the image end up in my jar?
    Quote Originally Posted by Norm View Post
    Use the jar command to put files in a jar file.
    Did you read that?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Runnable Jar Export cant make more than one JFrame
    By oinca in forum Advanced Java
    Replies: 5
    Last Post: 12-29-2011, 06:48 PM
  2. netbeans-make jars-prb
    By jlmp in forum Advanced Java
    Replies: 8
    Last Post: 09-30-2010, 04:08 AM
  3. Can not make a runnable jar of my project
    By liran in forum Advanced Java
    Replies: 5
    Last Post: 05-18-2010, 11:25 AM
  4. How to make a runnable jar with necessary libraries
    By Atriamax in forum New To Java
    Replies: 2
    Last Post: 10-27-2009, 10:36 PM
  5. Replies: 0
    Last Post: 08-19-2008, 04:44 PM

Posting Permissions

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