Results 1 to 19 of 19
Thread: Trying to make runnable jars
- 04-16-2012, 09:11 AM #1
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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

my game package contents:

Here is my manifest file:

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:

Thanks!
- 04-16-2012, 11:51 AM #2
Re: Trying to make runnable jars
Does Frame.java start with a package statement?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-16-2012, 11:54 AM #3
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Trying to make runnable jars
yes
Java Code:package game;
- 04-16-2012, 12:00 PM #4
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-16-2012, 12:09 PM #5
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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:
so how do I include these resources in my project and do i need to change the path to do so?Java Code:"src/images/picture.png" "src/sounds/soundEffect.wav"
Thanks!
- 04-16-2012, 12:10 PM #6
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Trying to make runnable jars
I meant include in my jar not my project
- 04-16-2012, 12:45 PM #7
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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?
- 04-16-2012, 01:14 PM #8
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.
- 04-16-2012, 01:22 PM #9
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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
- 04-16-2012, 01:27 PM #10
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.
- 04-16-2012, 01:36 PM #11
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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>
- 04-16-2012, 01:43 PM #12
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.
- 04-16-2012, 01:49 PM #13
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
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:

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
- 04-16-2012, 01:53 PM #14
Re: Trying to make runnable jars
Is that file for input only? It is not updated, just read?java.io.FileNotFoundException: src\game.txt
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.
- 04-16-2012, 01:58 PM #15
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Trying to make runnable jars
is getresource() a swing method and how do I "put them in the jar file"?
- 04-16-2012, 02:12 PM #16
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.
- 04-16-2012, 02:13 PM #17
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: Trying to make runnable jars
here is some of my Images in code:
would I do this?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();
or thisJava Code:URL myUrl = background.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?Java Code:URL myUrl = ic.getClass().getResource("src/images/space_background.png");
- 04-16-2012, 02:23 PM #18
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-16-2012, 02:24 PM #19
Similar Threads
-
Runnable Jar Export cant make more than one JFrame
By oinca in forum Advanced JavaReplies: 5Last Post: 12-29-2011, 06:48 PM -
netbeans-make jars-prb
By jlmp in forum Advanced JavaReplies: 8Last Post: 09-30-2010, 04:08 AM -
Can not make a runnable jar of my project
By liran in forum Advanced JavaReplies: 5Last Post: 05-18-2010, 11:25 AM -
How to make a runnable jar with necessary libraries
By Atriamax in forum New To JavaReplies: 2Last Post: 10-27-2009, 10:36 PM -
More efficient in memory? Multiple Jars or Single Jars with lot's of Classes
By dark_cybernetics in forum New To JavaReplies: 0Last Post: 08-19-2008, 04:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks