1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Java .jar - NoClassDefFound problems

Discussion in 'HTML, Graphics & Programming' started by adam3223, 2 May 2007.

  1. adam3223

    Gangster

    Joined: 22 Jul 2004

    Posts: 230

    Location: Nottingham, UK

    I've done a Java project using netbeans using the JDK1.5.
    It builds and creates a jar file which runs fine on my pc.

    However when I move it to the uni computers it doesn't work:
    (The uni computers hav JDK1.4 installed with netbeans 5.0RC2, but they also have JRE1.5)
    I get the following error

    >java -jar CarHire.jar
    ------ Starting Client Mode ------
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/swing/GroupLayout$Group
    at CarHire.Main.main(Main.java:29)

    It creates the following in the dist directory

    /dist/CarHire.jar
    /dist/lib/swing-layout-1.0.jar
    /dist/lib/AbsoluteLayout.jar

    The jar runs fine on my pc.

    Does anyone know how to get it to run?
     
  2. Rossmac

    Hitman

    Joined: 10 Nov 2005

    Posts: 650

    Location: Carrickfergus, N.Ireland

    ask the uni to update to 1.5? I think GroupLayout changed a bit going from 1.4 to 1.5
     
  3. SoapSurgeon

    Wise Guy

    Joined: 14 Apr 2003

    Posts: 1,101

    Have you set up your classpath correctly on the uni machines?
     
  4. adam3223

    Gangster

    Joined: 22 Jul 2004

    Posts: 230

    Location: Nottingham, UK

    They can't/won't. Due to the amount of red tape just to get anything installed.

    What is the correct class path to use?
     
  5. Psyk

    Sgarrista

    Joined: 18 Oct 2002

    Posts: 8,444

    Location: Leamington Spa

    Ah I can help here. GroupLayout unfortunately is not part of the standard libraries. You'll have to get hold of the swing-layout.jar file and put that in your classpath.

    edit- oops just realised you are including that file. Well you just have to make sure it's in the classpath when you run the jar.
     
  6. SoapSurgeon

    Wise Guy

    Joined: 14 Apr 2003

    Posts: 1,101

    I havent done java in a while but you have to make sure that all the jars you use are in your classpath so that when java tries to run your program it knows where to look for them.
     
  7. adam3223

    Gangster

    Joined: 22 Jul 2004

    Posts: 230

    Location: Nottingham, UK

    I've played around with the classpath but still can't get it to run:

    the Manifest file inside the jar contains the following:
    Code:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
    Main-Class: CarHire.Main
    X-COMMENT: Main-Class will be added automatically by build
    Class-Path: lib/swing-layout-1.0.jar
     
  8. SoapSurgeon

    Wise Guy

    Joined: 14 Apr 2003

    Posts: 1,101

    i suggest you look at line 29 in your main method (like the error tells you) to see what part it is having trouble with. You might be able to narrow it down to a particular jar that way.
     
  9. adam3223

    Gangster

    Joined: 22 Jul 2004

    Posts: 230

    Location: Nottingham, UK

    line 29 is basically
    frm = new frmMain();

    frmMain() errors out at the layout code for the form.
    I'm sure its just not finding the GroupLayout class.
     
  10. IdleWild

    Associate

    Joined: 5 May 2007

    Posts: 21

    Use the explicit path to the 1.5 JRE, it will be an updated API problem.

    Since the old JRE is also included in the JDK, it's probably calling the old since it will be in the environment paths.