Java Forum / General / February 2007
Jar file only works on my pc
stinkinrich88@googlemail.com - 03 Feb 2007 13:33 GMT Hello! I've created a jar file, works fine on my pc (in any directory) but won't work on anyone elses computer. (One person got the "can't find main class" message")
any ideas? this is the first time I've ever created a jar file
thanks!
Jeff - 03 Feb 2007 13:56 GMT On Feb 3, 8:33 am, stinkinric...@googlemail.com wrote:
> Hello! I've created a jar file, works fine on my pc (in any directory) > but won't work on anyone elses computer. (One person got the "can't [quoted text clipped - 3 lines] > > thanks! Need a lot more info. Does the jar contain more than one class? How are you creating the jar? A jar file contains a manifest file and a pile of classes. Have you looked at the jar to see what is inside? Do you call any classes in libraries (report generators, etc.)?
iherage - 03 Feb 2007 15:07 GMT On 2月3日, 下午2时33分, stinkinric...@googlemail.com wrote:
> Hello! I've created a jar file, works fine on my pc (in any directory) > but won't work on anyone elses computer. (One person got the "can't [quoted text clipped - 3 lines] > > thanks! My suggestion is to delete all the jar file and redo the process.
Alex Hunsley - 03 Feb 2007 15:56 GMT > On 2月3日, 下午2时33分, stinkinric...@googlemail.com wrote: >> Hello! I've created a jar file, works fine on my pc (in any directory) [quoted text clipped - 6 lines] > > My suggestion is to delete all the jar file and redo the process. If they do that, and recreate the jar in exactly the same way, they're most likely just going to be back at square one with the same problem.
Have google for Jars and manifest files. One decent page is http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html - read up on Manifest and the Main-class property. lex
Andy Dingley - 03 Feb 2007 16:05 GMT On 3 Feb, 13:33, stinkinric...@googlemail.com wrote:
> Hello! I've created a jar file, works fine on my pc (in any directory) > but won't work on anyone elses computer. As a wild guess, it's not the JAR that's at fault. Instead it probably has a dependency on something that your PC has installed on the classpath, but their's doesn't.
stinkinrich88@googlemail.com - 03 Feb 2007 23:18 GMT > On 3 Feb, 13:33, stinkinric...@googlemail.com wrote: > [quoted text clipped - 4 lines] > has a dependency on something that your PC has installed on the > classpath, but their's doesn't. ahh your joking!! I just posted a massive post and it didn't show up. I clicked "reply to author" and I think it went to Andy. Would you mind posting it for me please?? sorry! (thanks!)
Andy Dingley - 05 Feb 2007 11:02 GMT On 3 Feb, 23:18, stinkinric...@googlemail.com wrote:
> ahh your joking!! I just posted a massive post and it didn't show up. > I clicked "reply to author" and I think it went to Andy. Would you > mind posting it for me please?? sorry! (thanks!) Here you go:
On 3 Feb, 16:05, "Andy Dingley" <ding...@codesmiths.com> wrote:
> On 3 Feb, 13:33, stinkinric...@googlemail.com wrote: > [quoted text clipped - 4 lines] > has a dependency on something that your PC has installed on the > classpath, but their's doesn't. woooooww, sorry guys, why didn't I get an email telling me I had replies!? (I'm new to this forum) (sorry, group)
anyway, I'm pretty sure I have the right manistest thing. This is what I have:
Main-Class: ShutTheBox
in file name "yo" (yes! It has the extra line underneath it!) I had loads of trouble creating a jar because I didn't think i needed to include all the ShutTheBox$1.class files! I didn't know what they were! I have them up to $10. I think theyre somthing to do with my inner class actionListener things. But I include all of them now, and the 6 gif files I need.
(ohh, rant about google pages, it looses all the $'s so I can't upload an applet version there!)
Anyway, it works fine on my computer in any directory, with no other files in the directory. I open the jar file using 7zip and all the .class files and gifs are there. And there is a folder called META- INF with the manifest in it.
I use textpad to compile it and the command line jar cmf manifest hello.jar *.class *.gif to create it. Works fine.
Do you recon it's the actuall class? I've uploaded an applet version to http://www.txfiles.co.uk/rich/ShutTheBox.html. My mate couldn't get it working on there but, again, it work fine on my pc
thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Andy Dingley - 05 Feb 2007 11:14 GMT > On 3 Feb, 23:18, stinkinric...@googlemail.com wrote:
> I didn't think i needed to include all the ShutTheBox$1.class files! 1. Yes, you need them. They're to do with anonymous inner classes, typically generated by GUI code such as Swing. I'm surprised you didn't include these - I'd expect you to be surprised that they appeared, but wouldn't the natural assumption be that they're going to be important for something, even if you don't understand what?
2. Your system still has these on the classpath, even though they're not in the JAR. The JAR is broken on _both_ machines, but on your PC the rest of the environment compensates. Obviously they're not on the other machine, hence the failure.
3. Don't make JARs by hand. It's a painful process and it's horribly error prone. Right now would be a good time to learn some minimal use of Ant and to start getting into good habits about automatic builds, maybe even some automated unit testing.
Thorsten Kiefer - 03 Feb 2007 23:55 GMT Do you use JBuilder or Netbeans ?
> Hello! I've created a jar file, works fine on my pc (in any directory) > but won't work on anyone elses computer. (One person got the "can't [quoted text clipped - 3 lines] > > thanks! stinkinrich88@googlemail.com - 04 Feb 2007 00:02 GMT ok, quick note until andy posts my post:
I use textPad 4 to compile (so just javac) and command line to make jar. I open the jar file using 7zip and all of the class files are there (as in, the ShutTheBox.class and ShutTheBox$1-10.class (what are these for!!)) plus the gif files, plus a folder called META-INF with the manifest file in it. It works fine in any directory on my pc.
Do you recon it's the class file? My mate can't get the applet version on http://www.txfiles.co.uk/rich/ShutTheBox.html to work. can you? All my other applets work fine. Is it the stupid $ signs?
I think I have the $'s because of my actionListener inner classes. Is this a problem? good practice etc?
thanks!!!
iherage - 04 Feb 2007 02:10 GMT On 2月4日, 上午1时02分, stinkinric...@googlemail.com wrote:
> ok, quick note until andy posts my post: > [quoted text clipped - 12 lines] > > thanks!!! I think the $ is needed because when you write more than one classes in a file, java compiler will produce exact the same number of class files. I have encountered this kind of problems before. As I remembered I just carried out the procedure again and carefully followed the instruction provided by sun.
Andrew Thompson - 04 Feb 2007 05:53 GMT On Feb 4, 11:02 am, stinkinric...@googlemail.com wrote: ...
> I use textPad 4 to compile (so just javac) and command line to make > jar. I open the jar file using 7zip and all of the class files are > there (as in, the ShutTheBox.class and ShutTheBox$1-10.class (what are > these for!!)) Inner/anonymous classes.
>..plus the gif files, plus a folder called META-INF with > the manifest file in it. It works fine in any directory on my pc. The best way to prepare a jar is using the jar tool provideed with the SDK. Some other tools will use a less rigourous file structure, and offer non-standard forms of compression.
> Do you recon it's the class file? My mate can't get the applet version > onhttp://www.txfiles.co.uk/rich/ShutTheBox.htmlto work. can you? Yes it works fine for me, using Java 1.6. (or at least seems to - 'spinnable dice' appear etc.) Did your 'mate' get some console output? What was it?
Was this not originally a question about how to get an *application* working?
>..All > my other applets work fine. Is it the stupid $ signs? > > I think I have the $'s because of my actionListener inner classes. Is > this a problem? No - so long as they are all included.
>...good practice etc? 'Neither good nor bad' - it depends on the overall design whether it makes sense to have them. I do *not* believe this is the cause of the problem, unless you have not included them all.
One last thing.. 'One person got the "can't find main class" message"' ..If at all possible, get a copy/paste of that message.
Andrew T.
Andrew Thompson - 04 Feb 2007 05:57 GMT > On Feb 4, 11:02 am, stinkinric...@googlemail.com wrote: ....
> > Do you recon it's the class file? My mate can't get the applet version > > on http://www.txfiles.co.uk/rich/ShutTheBox.html towork. can you? > > Yes it works fine for me, using Java 1.6. Except of course, when I select 'Quit' from the menus.
This leads to a (perfectly explainable)..
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
Did this project start as an application, or applet?
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 10:39 GMT Hey! thanks for everyone's help!
I use the this command line to create the jar:
jar cmf yo hello.jar *.gif *.class
'cause my manifest is in a file called "yo"
is this the jar tool you were on about in the JDK?
Yeah, sorry! It is about an application, but I was wondering if it was a problem with the actual class rather than the jar as my friend couldn't even get the applet to work! I'll find out about any console output, thanks!
Andrew Thompson - 04 Feb 2007 11:03 GMT On Feb 4, 9:39 pm, stinkinric...@googlemail.com wrote:
> I use the this command line to create the jar: > [quoted text clipped - 3 lines] > > is this the jar tool you were on about in the JDK? It is best to quote a little of what you are replying to (if practical), to give context.
But if you are referring to my earlier comments, then 'yes'. That is certainly the command.
Note also that you were unsure if the '$' classes were a problem. That form of the command ('*.class') should find and include all the classes.
> Yeah, sorry! It is about an application, but I was wondering if it was > a problem with the actual class rather than the jar as my friend > couldn't even get the applet to work! Yes, but that applet is loose class files, not a jar file. (And it would be far better to package the classes into a jar, for any applet.)
Other thoughts. Since you obviously have a site, why not upload your jar to it, so we can have a look at it.
Also, I think this is well suited to a 'web start'* (JWS) launch, since you have a site, and it requires at least Java 1.2+ (JWS can handle the Java versioning for your friend, or at least, prompt them to update, if needed).
* e.g.'s <http://www.physci.org/jws/>
Note that a JWS launch might also be valuable for debugging.
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 11:13 GMT thanks a lot! Didn't know you could have jar applets, i'll look into it. Also, I will look into the webstart stuff.
here's the jar file: http://www.txfiles.co.uk/rich/hello.jar
thanks!
Andrew Thompson - 04 Feb 2007 13:12 GMT On Feb 4, 10:13 pm, stinkinric...@googlemail.com wrote:
> thanks a lot! Didn't know you could have jar applets, i'll look into > it. Also, I will look into the webstart stuff. *
> here's the jar file:http://www.txfiles.co.uk/rich/hello.jar Here's an example.. <http://www.physci.org/test/shutthebox/> ..or more specifically.. <http://www.physci.org/test/shutthebox/hello.jnlp>
That JNLP specifies a minimum Java of 1.6+, and gives a download URL from Sun. It is premature though, because at this moment, there is no 'auto download' available for 1.6, so if your friend would be willing to send you/us some screenshots, that would be most interesting.
The exact JNLP file shown there, is..
[hello.jnlp] <?xml version='1.0' encoding='UTF-8' ?> <jnlp spec='1.0' codebase='http://www.physci.org/test/shutthebox' href='hello.jnlp'> <information> <title>Shut The Box</title> <vendor>Stinkin' Rich</vendor> <description kind='one-line'> Test of the ShutTheBox application using Java 1.6+ </description> <offline-allowed /> </information> <resources> <j2se version='1.6+' href='http://java.sun.com/products/autodl/ j2se' /> <jar href='hello.jar' main='true' /> </resources> <application-desc main-class='ShutTheBox' /> </jnlp> [/hello.jnlp]
You would need to change the codebase, for your own site.
I noticed that the application does not resize very well. That indicate the layouts are used in a fragile way, or set to null, or something worse.
It would pay to fix the (underlying) problem, but failing that, you might set your frame to resizable 'false'.
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 14:24 GMT OK!
I've recompiled and re-jared the program using my university's computers (running 1.5) and it works!! On my friends computer! (and on mine too!). I will create a webstart as well! (thanks Andrew T for showing me how, It works on my home pc (1.6) but not here at uni (1.5) like you said.) I'll figure somthing out!
So we've solved the problem!! (but I'm not really sure why)
anyway, thanks for EVERYONE's help! and extra fast responses! I think I like this forum
feel free to play my game whenever you want, as a reward! haha
Rich
Andrew Thompson - 04 Feb 2007 14:42 GMT On Feb 5, 1:24 am, stinkinric...@googlemail.com wrote:
> OK! > > I've recompiled and re-jared the program using my university's > computers (running 1.5) and it works!! Yes. If you graba copy of the 1.5 rt.jar, you will be able to bild at home on the 1.6 machine as well (and still get 1.5 compatibility)
>....On my friends computer! (and on > mine too!). I will create a webstart as well! (thanks Andrew T for > showing me how, It works on my home pc (1.6) but not here at uni (1.5) > like you said.) Change the part of the JNLP that says '1.6+' to read '1.5+' and it should be set to go.
> feel free to play my game whenever you want, as a reward! haha To be honest, I still do not understand what it does, or is supposed to do. But then, I am not keen on games, and do not have the patience to try and figure them out. ;-)
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 11:08 GMT Ok, I have screen shots and console outputs! right, console output for java applet version from my freinds computer:
http://www.txfiles.co.uk/rich/appletConsoleOutput.txt
it's on about versions. I have jre 1.6 and she has 1.5 I thinik
ok, screenshot after opening the jar file:
http://www.txfiles.co.uk/rich/screen dump_cr.jpg
and the properties page of the jar:
http://www.txfiles.co.uk/rich/prop.jpg
(she clicked 'unblock' and still no luck!)
thanks!!
Andrew Thompson - 04 Feb 2007 11:18 GMT On Feb 4, 10:08 pm, stinkinric...@googlemail.com wrote:
> Ok, I have screen shots and console outputs! A picture speaks a thousand words (but note that text, where possible, does it in much less bandwidth!)
> right, console output for java applet version from my freinds > computer: ...
> it's on about versions. I have jre 1.6 and she has 1.5 I thinik First thing you need to find out, is what the minimum version for this code actually is. I would be surprised if it even needed Java 1.5, in order to run.
The (most definitive) way to find out, is to compile against an earlier rt.jar using the -bootclasspath option, then when you have found the minimum version, add the -source/target attributes for that version to javac as well. (Then use JWS to set the minimum version, and invoke an update if not installed.)
Is it open source?
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 11:36 GMT wow, that was pretty over my head I'm afraid!! I found this pdf trying to explain but it's no use http://www.javageeks.com/Papers/ BootClasspath/BootClasspath.pdf
She can access the other two applets on my site. Would it be helpful if I jared them and sent them to her? I have re-installed windows since making them so I may have a newer version of the jre or jdk. But I haven't used anything particularly complex (as you can see from the app)
my import statements:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.applet.*;
nothing very unusual (for me) apart from swing timers and anonamous inner classes (whatever they're called) these things:
Timer diceTm = new Timer(70, new ActionListener() { public void actionPerformed(ActionEvent e) {
and
ActionListener coverEv = new ActionListener(){public void actionPerformed(ActionEvent e) {
I'd prefer not to disclose all my code as it is a project for a whole module for my computer science degree. I don't want other people getting my code!! (ask if you want any other snippets) thanks!!
Andrew Thompson - 04 Feb 2007 12:39 GMT On Feb 4, 10:36 pm, stinkinric...@googlemail.com wrote:
> wow, that was pretty over my head I'm afraid!! I found this pdf trying > to explain but it's no usehttp://www.javageeks.com/Papers/ > BootClasspath/BootClasspath.pdf We can come back to that, but I have no PDF reader amd could not be bothered finding the 'convert to HTML' link for that.
> She can access the other two applets on my site. Would it be helpful > if I jared them and sent them to her? No. Not in their current form.
> ..I haven't used anything particularly complex (as you can see from the > app) No I cannot.
> my import statements: > > import javax.swing.*; Swing was introduced in 1.2, but had extra classes and attributes added in 1.4, and was consistently updated.
> import java.awt.*; Same thing - I do not believe there is a single Java version that had no changes to AWT. This tells us nothing.
> I'd prefer not to disclose all my code as it is a project for a whole > module for my computer science degree. Fair enough, but you might either - take this further, on your own PC, to determine the minimum version, and compile to that version (using a -bootclasspath). - wrap it in web start, and specify '1.6+', with a download URL for the JRE. - wrap it in web start/launch it as you do now, specify '1.5+', but compile for 1.5 using the -source/-target flags (and hope for the best).
Given it should only have a small distribution, I would be tempted to try the last (easiest) option.
Andrew T.
stinkinrich88@googlemail.com - 04 Feb 2007 11:36 GMT wow, that was pretty over my head I'm afraid!! I found this pdf trying to explain but it's no use http://www.javageeks.com/Papers/ BootClasspath/BootClasspath.pdf
She can access the other two applets on my site. Would it be helpful if I jared them and sent them to her? I have re-installed windows since making them so I may have a newer version of the jre or jdk. But I haven't used anything particularly complex (as you can see from the app)
my import statements:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.applet.*;
nothing very unusual (for me) apart from swing timers and anonamous inner classes (whatever they're called) these things:
Timer diceTm = new Timer(70, new ActionListener() { public void actionPerformed(ActionEvent e) {
and
ActionListener coverEv = new ActionListener(){public void actionPerformed(ActionEvent e) {
I'd prefer not to disclose all my code as it is a project for a whole module for my computer science degree. I don't want other people getting my code!! (ask if you want any other snippets) thanks!!
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|