Jar file only works on my pc

Discussion in 'Java' started by stinkinrich88@googlemail.com, Feb 3, 2007.

  1. Guest

    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!
     
    , Feb 3, 2007
    #1
    1. Advertising

  2. Jeff Guest

    On Feb 3, 8:33 am, 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
    > find main class" message")
    >
    > any ideas? this is the first time I've ever created a jar file
    >
    > 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.)?
     
    Jeff, Feb 3, 2007
    #2
    1. Advertising

  3. iherage Guest

    On 2ÔÂ3ÈÕ, ÏÂÎç2ʱ33·Ö, 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
    > find main class" message")
    >
    > any ideas? this is the first time I've ever created a jar file
    >
    > thanks!


    My suggestion is to delete all the jar file and redo the process.
     
    iherage, Feb 3, 2007
    #3
  4. Alex Hunsley Guest

    iherage wrote:
    > On 2ÔÂ3ÈÕ, ÏÂÎç2ʱ33·Ö, 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
    >> find main class" message")
    >>
    >> any ideas? this is the first time I've ever created a jar file
    >>
    >> thanks!

    >
    > 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
     
    Alex Hunsley, Feb 3, 2007
    #4
  5. Andy Dingley Guest

    On 3 Feb, 13:33, 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.
     
    Andy Dingley, Feb 3, 2007
    #5
  6. Guest

    On 3 Feb, 16:05, "Andy Dingley" <> wrote:
    > On 3 Feb, 13:33, 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.


    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!)
     
    , Feb 3, 2007
    #6
  7. Do you use JBuilder or Netbeans ?


    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
    > find main class" message")
    >
    > any ideas? this is the first time I've ever created a jar file
    >
    > thanks!
     
    Thorsten Kiefer, Feb 3, 2007
    #7
  8. Guest

    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!!!
     
    , Feb 4, 2007
    #8
  9. iherage Guest

    On 2ÔÂ4ÈÕ, ÉÏÎç1ʱ02·Ö, wrote:
    > 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
    > onhttp://www.txfiles.co.uk/rich/ShutTheBox.htmlto 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!!!


    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.
     
    iherage, Feb 4, 2007
    #9
  10. On Feb 4, 11:02 am, 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, Feb 4, 2007
    #10
  11. On Feb 4, 4:53 pm, "Andrew Thompson" <> wrote:
    > On Feb 4, 11:02 am, 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.
     
    Andrew Thompson, Feb 4, 2007
    #11
  12. Guest

    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!
     
    , Feb 4, 2007
    #12
  13. On Feb 4, 9:39 pm, wrote:

    > 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?


    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.
     
    Andrew Thompson, Feb 4, 2007
    #13
  14. Guest

    , Feb 4, 2007
    #14
  15. Guest

    , Feb 4, 2007
    #15
  16. On Feb 4, 10:08 pm, 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.
     
    Andrew Thompson, Feb 4, 2007
    #16
  17. Guest

    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!!
     
    , Feb 4, 2007
    #17
  18. Guest

    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!!
     
    , Feb 4, 2007
    #18
  19. On Feb 4, 10:36 pm, 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.
     
    Andrew Thompson, Feb 4, 2007
    #19
  20. On Feb 4, 10:13 pm, 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.
     
    Andrew Thompson, Feb 4, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lucy
    Replies:
    6
    Views:
    30,945
    steve
    Sep 7, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    630
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,785
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,862
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    699
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page