• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cant run JAR file

 
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, had a read through the tutorial and still no clearer so will check the versions
C
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this link
here
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic