aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Cant run JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cant run JAR file" Watch "Cant run JAR file" New topic
Author

Cant run JAR file

Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Hi,

Probably a fairly basic question here.
Should a jar file be able to run straight from a desktop of a PC if it has a JVM?
I Cant seem to run any jar files on a laptop although i have been able to run smaller programnes previously.
Keep getting error something like this:
'Cant open jar file, see console for errors'.... But I don't see any error notifications anywhere .
Must a JAR file contain only one main class?
Ta
Ciaran

I love deadlines, I love the whooshing sound they make as they fly by...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Please show us the instructions you are using to open the .jar files.
How are you specifying the class with the main method? Is it in the manifest file? Have you set up a file association between .jar and javaws?

You will find much more useful information in the Java Tutorials.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

yes, you should be able to double-click the icon on your desktop to run the program
a problem i had for a while is i was compiling using java 7 but i still had the java 6 JRE. getting rid of that and getting the java 7 JRE fixed it.
your jar command should look like this
jar cmf manifest-file jar-file input-files
your manifest file should resemble this
Manifest-Version: 1.0
Main-Class: Paint

SCJP
Visit my download page
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Thanks, had a read through the tutorial and still no clearer so will check the versions
C
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

try this link
here
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Thanks the link was very useful and clear.
So i moved all classes, resources, and java files to sane directory, used the commands outlined in the terminal window and there was no errors returned.

But I can't seem to find any jar file in the directory...
Does the terminal window give a default file name when it builds the file or are we supposed to define one somewhere....
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

jar cmf manifest-file jar-file input-files
most likely you failed to specify the name of the jar file. i did that just the other day. mine looks like this:
jar cmf Manifest.mf paint.jar Paint.class.....etc
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Cheers got that, so it seems I can create the jar file and I can get its contents as below, but you will see when I try to access I get a 'following errors':
The manifest file reads as:
Manifest-Version: 1.0
Main-Class: TestDraw




and if i look for class path:
bash-3.2$ java cp TestDraw.jar com.app.Test
Error: Could not find or load main class cp
bash-3.2$
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Got it

My problem was I was putting the main-class files in the same project folder as he non-main classes (Java Class Library).
Separating the main class into a separate Java Application folder, then adding the JAR file from the non-main class project solved it.

However, the JAR file runs from the directory where I have saved it on my PC but not when I copy and paste to my Desktop.
Is this something to do with the class path?

Is it possible to email someone the JAR file who has JRE installed so they can run the application on a seperate PC?

Thanks

Ciaran
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Ciaran Mooney wrote:However, the JAR file runs from the directory where I have saved it on my PC but not when I copy and paste to my Desktop.

So what errors do you see on the console, when you say it doesn't run on your desktop. Please copy paste the stack trace here.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Hi Maneesh,

So it works fine when I double click the JAR file form the directory it is saved in through netbeans.

However, when I double click the JAR on desktop I get a 'The Java JAR file "Ass1Part5Test.jar" could not be launched. Check console for possible error messages." via a dialog box.
If I run from terminal window the exception thread is as follows:



Very similar to the orginal thread I was seeing with the orginal problem dicussed earlier.
When I look for contents of JAR file on desktop I get:



which is the same as the working JAR file in the in other (netbean)cdirectory:


any ideas?

Thanks in advance
C
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

Got it, was simply forgetting to include the lib/file.jar that was the library for the main jar file.

Thanks for yer help and patience

C
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cant run JAR file